用Javascript支持筛选scrape的好工具是什么?

2024-05-23 18:59:12 发布

您现在位置:Python中文网/ 问答频道 /正文

是否有一个好的测试套件或工具集可以自动进行网站导航(有Javascript支持)并从页面中收集HTML?

当然,我可以用BeautifulSoup直接创建HTML。但这对需要Javascript的站点没有好处。:)


Tags: 套件站点网站html页面javascript工具集beautifulsoup
3条回答

您可以使用SeleniumWatir来驱动真正的浏览器。

还有一些基于JavaScript的无头浏览器:

  • PhantomJS是一个无标题的Webkit浏览器。
    • pjscrape是一个基于PhantomJS和jQuery的刮削框架。
    • CasperJS是一个基于PhantomJS的导航脚本和测试实用程序,如果您需要在要擦掉的url上做一点以上的工作的话。
  • Zombie用于Node.js

就我个人而言,我最熟悉的是Selenium,它支持用大量的语言编写自动化脚本,并且有更成熟的工具,比如Firefox优秀的Selenium IDE扩展,可以用来编写和运行测试用例,还可以将测试脚本导出到多种语言。

使用HtmlUnit也是一种可能性。

HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.

It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating either Firefox or Internet Explorer depending on the configuration you want to use.

It is typically used for testing purposes or to retrieve information from web sites.

Selenium现在包装htmlunit,这样您就不需要再启动浏览器了。新的WebDriver api也很容易使用。The first example use htmlunit driver

相关问题 更多 >