HTTP POST和使用Scrapy解析JSON

Cry*_*pto 4 python json web-crawler scrapy

我有一个网站,我想从中提取数据.数据检索非常简单.

它使用HTTP POST获取参数并返回JSON对象.所以,我有一个我想要做的查询列表,然后以一定的间隔重复更新数据库.scrapy适合这个还是我应该使用其他东西?

我实际上不需要关注链接,但我确实需要同时发送多个请求.

Rol*_*Max 7

看起来像POST请求怎么样?有许多变体,如简单查询参数(?a=1&b=2),类似形式的有效负载(正文包含a=1&b=2)或任何其他类型的有效负载(正文包含某种格式的字符串,如json或xml).

在scrapy中发出POST请求相当简单,请参阅:http://doc.scrapy.org/en/latest/topics/request-response.html#request-usage-examples

例如,您可能需要以下内容:

    # Warning: take care of the undefined variables and modules!

    def start_requests(self):
        payload = {"a": 1, "b": 2}
        yield Request(url, self.parse_data, method="POST", body=urllib.urlencode(payload))

    def parse_data(self, response):
        # do stuff with data...
        data = json.loads(response.body)
Run Code Online (Sandbox Code Playgroud)