Python爬虫——scrapy_post请求

import scrapy
import json


class TestpostSpider(scrapy.Spider):
    name = "testpost"
    allowed_domains = ["fanyi.baidu.com"]
    # start_urls = ["https://fanyi.baidu.com/sug"]
    #
    # def parse(self, response):
    #     pass


    def start_requests(self):
        url = 'https://fanyi.baidu.com/sug'

        data = {
            'kw': 'hello'
        }

        yield scrapy.FormRequest(url=url, formdata=data, callback=self.parse_second)


    def parse_second(self, response):
        content = response.text
        obj = json.loads(content)
        print(obj)

你可能感兴趣的:(Python爬虫,python,爬虫,scrapy)