How do you replace HTML tags with commas (for CSV) in Python?
<p>I have an extremely long HTML file that I cannot modify but would like to parse for CSV output. Imagine the following code repeated hundreds of times all on the same line. I realize this would be much simpler if there were line breaks, but I have no control over how the file is created. You should also know that there are no friendly line breaks in this code; imagine fully minified code. I have just added breaks so it's easier to visualize. But, any actual solution to this would not be able to rely on line breaks or spaces since they will not exist in reality.</p>

<pre><code>&lt;tr id="link"&gt;
&lt;td&gt;&lt;a href="https://www.somewebsite.com" target="_target"&gt;Title&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Value 1&lt;/td&gt;&lt;td style="width:20ch"&gt;Value 2&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;Value 3&lt;/td&gt;
&lt;td&gt;Value 4&lt;/td&gt;&lt;td&gt;Value 5&lt;/td&gt;&lt;td&gt;Value 6&lt;/td&gt;
&lt;td&gt;Value 7&lt;/td&gt;&lt;td&gt;Value 8&lt;/td&gt;&lt;td&gt;Value 9&lt;/td&gt;&lt;/tr&gt;
</code></pre>

<p>My desired output from this is <code>https://www.somewebsite.com, Title, Value 1, Value 2, , , Value 3, ...</code> (etc.)</p>

<p>Basically, I want to replace all values in tags with commas but retain the URL. I cannot find any way in Python to parse something like this since the scan(), find(), etc. functions in Python do not seem to keep track of the file pointer globally as I'm used to in languages like C. So, no matter what I do I'm continually just looking at the beginning of the line.</p>