简体   繁体   English

使用JSOUP在HTML表中选择链接

[英]Select link in HTML table using JSOUP

How can I click on a link in an HTML table using Jsoup and load the document. 如何使用Jsoup在HTML表中单击链接并加载文档。 I was able to obtain the href but it's not properly formatted so i can't load the page. 我可以获取href,但格式不正确,因此无法加载页面。

Element table = doc.select("table.dxgvTable_Office2010Blue");
Elements l = table.select("a");
for(Element links : l){
    System.out.println(links.text() + "\t" + links.attr("href"));
}

Below is the html code for every row in the table 以下是表格中每一行的html代码

</tr><tr id="ctl00_pageMain_dataGrid_DXDataRow8" class="dxgvDataRow_Office2010Blue">
                        <td class="dxgv"><a class="dxeHyperlink_Office2010Blue" href="javascript:focusedRowField.Set(&#39;row&#39;, dataGridClient.GetRowKey(dataGridClient.GetFocusedRowIndex())); drilldown_button.DoClick();">Canadian Short Term Fixed Income</a></td><td class="dxgv" align="right">47,591</td><td class="dxgv" align="right">4.21 %</td><td class="dxgv" align="right">260.2</td><td class="dxgv" align="right">0.55%</td><td class="dxgv" align="right">2,154.9</td><td class="dxgv" align="right">44,970</td><td class="dxgv" align="right">4.79%</td><td class="dxgvHEC"></td>

How do I click on the Link 'Canadian Short Term Fixed Income' if the output below is what is saved in href? 如果以下输出是href中保存的内容,如何单击“加拿大短期固定收益”链接?

javascript:focusedRowField.Set('row',
    dataGridClient.GetRowKey(dataGridClient.GetFocusedRowIndex()));  
drilldown_button.DoClick();

How can i perform the click on the url using Java? 如何使用Java执行网址点击?

You can't click on a button with JSoup. 您无法使用JSoup单击按钮。 JSoup is a parser to extract/manipulate the information but you can't trigger an action and have the associated javascript executed. JSoup是一个解析器,用于提取/处理信息,但是您无法触发动作并执行关联的javascript。

One easy way to achieve that would be to use a tool to automate a real browser, something like Selenium . 一种简单的实现方法是使用一种工具来使真正的浏览器自动化,例如Selenium

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM