Xpath Scrapy follow javascript输入按钮
我在页面上有以下输入:Xpath Scrapy follow javascript输入按钮,xpath,web-scraping,scrapy,scrapy-spider,Xpath,Web Scraping,Scrapy,Scrapy Spider,我在页面上有以下输入: <input name="ct99" value="" id="ct99" class="GetData" type="submit"> <input name="ct92" value="" id="ct92" class="GetData" type="submit"> <input name="ct87" value="" id="ct87" class="GetData" type="submit"> 解决此问题有两种常见方法
<input name="ct99" value="" id="ct99" class="GetData" type="submit">
<input name="ct92" value="" id="ct92" class="GetData" type="submit">
<input name="ct87" value="" id="ct87" class="GetData" type="submit">
解决此问题有两种常见方法:
- 使用浏览器开发工具(网络选项卡),在单击特定按钮时检查发送的请求,然后使用
或scrapy.request
scrapy.FormRequest
- 使用以下操作自动化浏览器:找到按钮并单击它,然后抓取
并实例化.page\u source
实例,请参见此处的示例:选择器
find_elements_by_xpath
(注意s
)。我使用self.driver=webdriver.Firefox(),但它关闭时出错“StaseLeEngultEnguleExp:Exist:Case:Cache中没有找到的元素——可能是自从查找后页面已经改变了”“任何提示?”GORANN请考虑单独提出一个问题,并尽可能提供尽可能多的细节。谢谢!
def parse(self, response):
sel = Selector(response)
links = sel.xpath("//input[@class='GetData']").extract()
for data in links:
yield scrapy.FormRequest.from_response(response,
formdata={}, callback=self.after_click)
def after_click(self, response):
url = response.url
print '\nURL', url