scrapy提交关键字请求

时间:2021-11-29 17:02:08

提交查询关键字的请求

 1 import scrapy
 2 
 3 
 4 class PostSpider(scrapy.Spider):
 5     name = 'post'
 6     # allowed_domains = ['www.xxx.com']
 7     start_urls = ['https://fanyi.baidu.com/sug']
 8 
 9     def start_requests(self):
10         data = {
11             'kw':'python'
12         }
13         for url in self.start_urls:
14             yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse)
15 
16     def parse(self, response):
17         print(response.text)

这里重写父类的start_requests方法