[HtmlUnit] [htmlunit:bugs] #2013 xpath returning more content than belongs in HtmlDivision

RBRi via HtmlUnit-develop <[email protected]> Sat, 30 Mar 2019 17:45:51 -0000
Newsgroups gmane.comp.java.htmlunit.devel
Message-ID </p/htmlunit/bugs/2013/495a4e513d75c1502ae8d660c5f3417da5d4ffa7.bugs@htmlunit.p.sourceforge.net>
This is a multi-part message in MIME format.
--===============5777541162506066675==
Content-Type: multipart/related;
 boundary="===============4954259319424826605=="

This is a multi-part message in MIME format.
--===============4954259319424826605==
Content-Type: multipart/alternative;
 boundary="===============0948694334597502962=="
MIME-Version: 1.0

--===============0948694334597502962==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

- **status**: open --> closed
- **assigned_to**: RBRi



---

** [bugs:#2013] xpath returning more content than belongs in HtmlDivision**

**Status:** closed
**Group:** 2.34.1
**Created:** Sat Mar 30, 2019 05:21 PM UTC by arya
**Last Updated:** Sat Mar 30, 2019 05:45 PM UTC
**Owner:** RBRi


I'm getting unussual results

I have the following HTMLUnit script which is supposed to extract the zipcode hrefs.


~~~
WebClient webClient = new WebClient();
webClient.getOptions().setJavaScriptEnabled(false);

HtmlPage countyPage = webClient.getPage("https://www.realtor.com/propertyrecord-search/Autauga-County_AL");

HtmlDivision zipCodesDiv = (HtmlDivision) countyPage
		.getByXPath("//h3[contains(., \"Zip Codes\")]/following::div[1]").get(0);

System.out.println(zipCodesDiv.asXml());

List<HtmlAnchor> zipcodeLinks = zipCodesDiv.getByXPath("//li/a[contains(@href,'propertyrecord-search/')]");

System.out.println("Zipcode link size: " + zipcodeLinks.size());
for (int zipcodeCount = 0; zipcodeCount < zipcodeLinks.size(); zipcodeCount++) {
	System.out.println(zipcodeLinks.get(zipcodeCount));
}
~~~

zipCodesDiv contains the div that contains the zipcodes, however 

zipCodesDiv.getByXPath("//li/a[contains(@href,'propertyrecord-search/')]");

is returning more content than it belongs in zipCodesDiv, it's also returning cities in Autauga County. Why is this happening? Is this a bug?


---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
--===============0948694334597502962==
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit

<div class="markdown_content"><ul>
<li><strong>status</strong>: open --&gt; closed</li>
<li><strong>assigned_to</strong>: RBRi</li>
</ul>
<hr/>
<p><strong> <a class="alink strikethrough" href="https://sourceforge.net/p/htmlunit/bugs/2013/">[bugs:#2013]</a> xpath returning more content than belongs in HtmlDivision</strong></p>
<p><strong>Status:</strong> closed<br/>
<strong>Group:</strong> 2.34.1<br/>
<strong>Created:</strong> Sat Mar 30, 2019 05:21 PM UTC by arya<br/>
<strong>Last Updated:</strong> Sat Mar 30, 2019 05:45 PM UTC<br/>
<strong>Owner:</strong> RBRi</p>
<p>I'm getting unussual results</p>
<p>I have the following HTMLUnit script which is supposed to extract the zipcode hrefs.</p>
<div class="codehilite"><pre><span></span><span class="nt">WebClient</span> <span class="nt">webClient</span> <span class="o">=</span> <span class="nt">new</span> <span class="nt">WebClient</span><span class="o">();</span>
<span class="nt">webClient</span><span class="p">.</span><span class="nc">getOptions</span><span class="o">()</span><span class="p">.</span><span class="nc">setJavaScriptEnabled</span><span class="o">(</span><span class="nt">false</span><span class="o">);</span>

<span class="nt">HtmlPage</span> <span class="nt">countyPage</span> <span class="o">=</span> <span class="nt">webClient</span><span class="p">.</span><span class="nc">getPage</span><span class="o">(</span><span class="s2">"https://www.realtor.com/propertyrecord-search/Autauga-County_AL"</span><span class="o">);</span>

<span class="nt">HtmlDivision</span> <span class="nt">zipCodesDiv</span> <span class="o">=</span> <span class="o">(</span><span class="nt">HtmlDivision</span><span class="o">)</span> <span class="nt">countyPage</span>
        <span class="p">.</span><span class="nc">getByXPath</span><span class="o">(</span><span class="err">"</span><span class="o">//</span><span class="nt">h3</span><span class="cp">[</span><span class="nx">contains</span><span class="p">(</span><span class="nx">.</span><span class="p">,</span> <span class="o">\</span><span class="s2">"Zip Codes</span><span class="se">\"</span><span class="s2">)]/following::div[1]"</span><span class="p">)</span><span class="bp">.</span><span class="nb">get</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>

<span class="nx">System.out.println</span><span class="p">(</span><span class="nx">zipCodesDiv.asXml</span><span class="p">());</span>

<span class="kt">List</span><span class="o">&lt;</span><span class="nx">HtmlAnchor</span><span class="o">&gt;</span> <span class="n">zipcodeLinks</span><span class="o"> =</span> <span class="nx">zipCodesDiv.getByXPath</span><span class="p">(</span><span class="s2">"//li/a[contains(@href,'propertyrecord-search/')]"</span><span class="p">);</span>

<span class="nx">System.out.println</span><span class="p">(</span><span class="s2">"Zipcode link size: "</span> <span class="o">+</span> <span class="nx">zipcodeLinks.size</span><span class="p">());</span>
<span class="nx">for</span> <span class="p">(</span><span class="nx">int</span> <span class="n">zipcodeCount</span><span class="o"> =</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">zipcodeCount</span> <span class="o">&lt;</span> <span class="nx">zipcodeLinks.size</span><span class="p">();</span> <span class="nx">zipcodeCount</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">System.out.println</span><span class="p">(</span><span class="nx">zipcodeLinks.get</span><span class="p">(</span><span class="nx">zipcodeCount</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>


<p>zipCodesDiv contains the div that contains the zipcodes, however </p>
<p>zipCodesDiv.getByXPath("//li/a<span>[contains(@href,'propertyrecord-search/')]</span>");</p>
<p>is returning more content than it belongs in zipCodesDiv, it's also returning cities in Autauga County. Why is this happening? Is this a bug?</p>
<hr/>
<p>Sent from sourceforge.net because [email protected] is subscribed to <a href="https://sourceforge.net/p/htmlunit/bugs/">https://sourceforge.net/p/htmlunit/bugs/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/htmlunit/admin/bugs/options.">https://sourceforge.net/p/htmlunit/admin/bugs/options.</a>  Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>
--===============0948694334597502962==--
--===============4954259319424826605==--


--===============5777541162506066675==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============5777541162506066675==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop

--===============5777541162506066675==--