简体   繁体   English

如何在scrapy蜘蛛的start_urls中发送帖子数据

[英]How to send post data in start_urls of the scrapy spider

I want to crawl a website which supports only post data. 我想抓取一个只支持发布数据的网站。 I want to send the query params in post data in all the requests. 我想在所有请求中的post数据中发送查询参数。 How to achieve this? 怎么做到这一点?

POST requests can be made using scrapy's Request or FormRequest classes. POST请求可以使用scrapy的RequestFormRequest类进行。

Also, consider using start_requests() method instead of start_urls property. 另外,请考虑使用start_requests()方法而不是start_urls属性。

Example: 例:

from scrapy.http import FormRequest

class myspiderSpider(Spider):
    name = "myspider"
    allowed_domains = ["www.example.com"]

    def start_requests(self):
        return [ FormRequest("http://www.example.com/login",
                     formdata={'someparam': 'foo', 'otherparam': 'bar'},
                     callback=self.parse) ]

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM