Я пытаюсь научиться Scrapy. Я попытался повторить приведенный ниже запрос в Scrapy, но это не сработало. Я тоже пробовал scrapy.Request(method='POST')
, но он тоже не работал.
import requests, json
headers = {
'accept': '*/*',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'content-length': '132',
'content-type': 'application/x-www-form-urlencoded',
'origin': 'https://www.autozone.com',
'referer': 'https://www.autozone.com/miscellaneous-non-automotive/jump-starter',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
'x-requested-with': 'XMLHttpRequest'
}
url = 'https://www.autozone.com/rest/bean/autozone/diy/commerce/pricing/PricingServices/retrievePriceAndAvailability?atg-rest-depth=2'
data = {
'arg1': '9801',
'arg2': '',
'arg3': '824997',
'arg4': ''
}
response = requests.post(url, headers=headers, data=data, timeout=5)
info = json.loads(response.text)
print(info['atgResponse'][0]['retailPrice']) # prints 129.99
Scrapy Shell:
> r = scrapy.FormRequest(url, formdata=data, headers=headers)
> fetch(r) # Doesn't work
Может кто-нибудь указать, где я ошибаюсь
Редактировать 1:
Вот стэк следа scrapy. Надеюсь, это поможет.
>>> fetch(r)
2020-02-15 15:00:08 [scrapy.core.engine] INFO: Spider opened
2020-02-15 15:03:08 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <POST https://www.autozone.com/rest/bean/autozone/diy/commerce/pricing/PricingServices/retrievePriceAndAvailability?atg-rest-depth=2> (failed 1 times): User timeout caused connection failure: Getting https://www.autozone.com/rest/bean/autozone/diy/commerce/pricing/PricingServices/retrievePriceAndAvailability?atg-rest-depth=2 took longer than 180.0 seconds..
Он повторяется несколько раз, а затем не удается.
Спасибо.