【问题标题】:How do I get past an accept dialog using scrapy?如何使用 scrapy 通过接受对话框?
【发布时间】:2014-09-11 22:38:39
【问题描述】:

我需要抓取一个包含我需要先通过的接受对话框的网站。形式如下:

单击接受按钮会将我带到包含我需要解析的表格的页面。现在我有:

# function to parse markup
def parse(self, response):        
    yield FormRequest(url="http://www.somedomain.com/lst_sale",
                      method="POST",
                      formdata={},
                      callback=self.parse_list)


def parse_list(self, response):
    # do something...

问题是 parse_list 永远不会被调用,所以我假设表单发布没有发生。关于如何让它发挥作用的任何想法?

谢谢!

【问题讨论】:

  • 我现在明白这是一个 cookie 问题。我曾尝试使用 yield FormRequest.from_response(response, clickdata={ "value" : "Accept"}, callback=self.parse_list) 但这也不起作用。想法?

标签: scrapy


【解决方案1】:

找到了答案。原来我没有发送正确的值。现在使用:

def parse(self, response):
    yield FormRequest.from_response(
                    response, 
                    formdata={"value":"Accept"}, 
                    callback=self.after_accept)

def after_accept(self, response):
    yield Request("http://example.com?some_vars=some_values", callback=self.parse_list)

def parse_list(self, response):
    #begin scraping!

这将为我处理 ASP.NET_SessionId。我在 settings.py 中设置了 COOKIES_DEBUG = True ,这表明我确实正在处理会话 - 这让我找到了问题的根源。我希望。

【讨论】:

    猜你喜欢
    • 2021-04-24
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-13
    • 2023-02-16
    相关资源
    最近更新 更多