import scrapy import json class TestpostSpider(scrapy.Spider): name = 'testpost' allowed_domains = ['https://fanyi.baidu.com/sug'] # post请求 如果没有参数 那么这个请求将没有任何意义 # 所以start_urls 也没有用了 # parse方法也没有用了 # start_urls = ['https://fanyi.baidu.com/sug/'] # # def parse(self, response): # pass def start_requests(self): url = 'https://fanyi.baidu.com/sug' data = { 'kw': 'final' } yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse_second) def parse_second(self,response): content = response.text obj = json.loads(content,encoding='utf-8') print(obj)
标签:sug,请求,self,parse,start,scrapy,post,response From: https://www.cnblogs.com/zhaolei0419/p/17026188.html