因为我是python和scrapy的新手。我一直在尝试抓取一个 URL 碎片化的网站。我正在发出发布请求以获取响应,但不幸的是它没有让我得到结果。
def start_requests(self):
try:
form = {'menu': '6'
, 'browseby': '8'
, 'sortby': '2'
, 'media': '3'
, 'ce_id': '1428'
, 'ot_id': '19999'
, 'marker': '354'
, 'getpage': '1'}
head = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
# 'Content-Length': '78',
# 'Host': 'onlinelibrary.ectrims-congress.eu',
# 'Accept-Encoding': 'gzip, deflate, br',
# 'Connection': 'keep-alive',
'XMLHttpRequest':'XMLHttpRequest',
}
urls = [
'https://onlinelibrary.ectrims-congress.eu/ectrims/listing/conferences'
]
request_body = urllib.parse.urlencode(form)
print(request_body)
print(type(request_body))
for url in urls:
req = Request(url=url, body= request_body, method='POST', headers=head,callback=self.parse)
req.headers['Cookie'] = 'js_enabled=true; is_cookie_active=true;'
yield req
except Exception as e:
print('the error is {}'.format(e))
我收到一个不断的错误
[scrapy.downloadermiddlewares.retry] ERROR: Gave up retrying <POST https://onlinelibrary.ectrims-congress.eu/ectrims/listing/conferences> (failed 4 times): 400 Bad Request
当我试图让邮递员检查相同的内容时,我得到了预期的输出。有人可以帮我解决这个问题。