有没有可能把pyexecjs和scrapy一起使用?

2024-09-29 01:18:55 发布

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

不久前我偶然发现了pyexecjs,我想知道它是否可以与scrapy一起使用来抓取JS生成的数据。 https://github.com/doloopwhile/PyExecJS

我检查了库应该如何使用的示例,但我不确定如何将它与scrapy集成。在


Tags: 数据httpsgithubcom示例jsscrapypyexecjs
1条回答
网友
1楼 · 发布于 2024-09-29 01:18:55

我强烈建议你试试硒与幻影。下面是一个示例代码。在

from selenium import webdriver

url = "http://www.taobao.com/"
browser = webdriver.PhantomJS()
browser.get(url)
input = browser.find_element_by_xpath("//input[@id='q']")
bnt = browser.find_element_by_xpath("//button[@class='btn-search']")
input.send_keys("watch")
bnt.submit()

有关API的详细信息,请参阅WebDriver API 至于如何将selenium与scrapy集成,我的建议是将其嵌入到you spider的parse函数中。例如:

相关问题 更多 >