Scrapy使用“请求”发出的相同请求不适用于Scrapy

2024-05-01 23:56:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用scrapy做一个POST请求,但是当我用失眠或'requests'库做请求时,得到的响应不一样

My code with 'requests' lib:

import requests

formdata={'UF':'AM'}
response = requests.post('http://www.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaFaixaCep.cfm', data=formdata)

print(response.text) #this is the response i want

My code with scrapy:

import scrapy


class Get_uf_ceps(scrapy.Spider):
    name = 'quotes'

    def start_requests(self):
        url = 'http://www.buscacep.correios.com.br/sistemas/buscacep/resultadoBuscaFaixaCep.cfm'

        formdata = {
            'UF': 'AM'
        }
        yield scrapy.FormRequest(url, formdata=formdata)

    def parse(self, response):
        print(response.text) # this response is not the same that i got with 'requests'

I want this table as a response, but it only get returned with insomnia or requests


Tags: importhttpresponsemywwwwithcodethis