P
Paul
Hi there, I'm using net/http to retrieve some html pages and now I
want to count the number of items in a list on the page. The
response.body is stored as a string.
The HTML looks something like this:
----
<div class="first section">
<h1>
Section Heading I'm interested in:
</h1>
<ul>
<li>
<form action="foo" method="post" name="">
<button type="submit">foo</button>
</form>
</li>
<li>
<form action="bar" method="post" name="">
<button type="submit">bar</button>
</form>
</li>
</ul>
</div>
<div class="next section">
----
So what I want to do is count the number of li's in a particular div
section. In this case the answer is 2. It might be more, it might be
0.
I can find the section I want with a regex but I don't know how to
iterate through the string looking for particular elements. I was
thinking about taking the section I'm interested in and saving it as
an array and then iterating through each array element (html line)
that way, but I thought there might be a quicker way to do it.
suggestions?
TIA
want to count the number of items in a list on the page. The
response.body is stored as a string.
The HTML looks something like this:
----
<div class="first section">
<h1>
Section Heading I'm interested in:
</h1>
<ul>
<li>
<form action="foo" method="post" name="">
<button type="submit">foo</button>
</form>
</li>
<li>
<form action="bar" method="post" name="">
<button type="submit">bar</button>
</form>
</li>
</ul>
</div>
<div class="next section">
----
So what I want to do is count the number of li's in a particular div
section. In this case the answer is 2. It might be more, it might be
0.
I can find the section I want with a regex but I don't know how to
iterate through the string looking for particular elements. I was
thinking about taking the section I'm interested in and saving it as
an array and then iterating through each array element (html line)
that way, but I thought there might be a quicker way to do it.
suggestions?
TIA