Scrapy:发送http请求并解析响应

时间:2012-07-01 09:58:30

标签: http scrapy

我查看了scrapy docs,但是scrapy可以发送http表单(例如:用户名,密码,......)并解析发送此表单的结果吗?

1 个答案:

答案 0 :(得分:1)

同一页面中有一个示例:http://scrapy.readthedocs.org/en/latest/topics/request-response.html#passing-additional-data-to-callback-functions

def parse_page1(self, response):
    item = MyItem()
    item['main_url'] = response.url
    request = Request("http://www.example.com/some_page.html",
                      callback=self.parse_page2)
    request.meta['item'] = item
    return request

def parse_page2(self, response):
    item = response.meta['item']
    item['other_url'] = response.url
    return item

您只需将回调参数函数传递给请求,然后在parse_page2中解析结果;)