![](/img/trans.png)
[英]how to get javascript code too with the actual source with Html Agility Pack
[英]html agility pack is returning javascript code except the actual Html
我想从使用HTML敏捷包的网站上使用C#控制台获取链接,但是有用li和href标记编写的Java脚本代码,为什么Java脚本在单击时会更改代码,我不知道,请告诉我解决方案如何获取实际代码
<li onmouseover="activate_menu('top-menu-61', 61); void(0);" onmouseout="deactivate_menu('top-menu-61', 61);"><a href="javascript:void();
我可以在li和一个标签中看到它,如何解决这个问题并获取实际的html,这样我就可以得到更多的链接
在将其传递给HtmlAgilityPack进行解析之前,请尝试使用诸如Selenium WebDriver之类的浏览器自动化工具来利用真实的浏览器完全生成网页。 如以下示例所示,使用Selenium应该非常容易。 您只需要确保预先正确安装了所有必需的工具(Selenium库和选择的浏览器驱动程序):
// Initialize the Chrome Driver (or any other supported browser)
using (var driver = new ChromeDriver())
{
// open the target page
driver.Navigate().GoToUrl("the_targt_page_url_here");
//maybe add selenium waits if needed,
//to wait until certain element appear in the page
//pass the HTML page to HAP's HtmlDocument
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(driver.PageSource);
}
Selenium还提供了在页面中定位元素的方法,因此可以根据需要用Selenium完全替换HAP。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.