Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath Scrapy follow javascript输入按钮_Xpath_Web Scraping_Scrapy_Scrapy Spider - Fatal编程技术网

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
    并实例化
    选择器
    实例,请参见此处的示例:


您需要在下一个请求中传递表单url,您有所有的html吗?没有,我没有比这些输入字段更多的内容。谢谢。我使用selenium,但是如何迭代输入?我有错误类型error:'WebElement'对象不是iterable links=self.driver.find_element_by_xpath(“//input[@class='GetData'])@Goran当然,使用
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