1、可以使用`yield scrapy.FormRequest(url,formdata,callback)`方法发送POST请求。
其中构造参数formdata可以是字典,也可以是可迭代的(key,value)元组,代表着需要提交的表单数据。
2、如果希望程序执行一开始就发送POST请求,可以重写Spider类的`start_requests(self)`方法,并且不再调用start_urls里的url。
class mySpider(scrapy.Spider): # start_urls = ["http://www.example.com"] def start_requests(self): url = "http://www.xxxx.com/xxx" # FormRequest是Scrapy发送POST请求的方法 yield scrapy.FormRequest( url = url, formadata={"email":"...",'password':"..."}, callback = self.parse_page ) def parse_page(self,response): # do something
3、实现方式