Я пишу <Spider>
, и после успешного входа в систему в <parse_login>
я пытаюсь отправить <FormRequest>
по ответу <parse_login>
. Я получил куки от ответа <parse_login>
, и попытался добавить куки в <FormRequest>
, но это не удалось, что вызывает перенаправление на страницу входа.
# here is the method after `parse_login()`
# form data
def query_form(self, response: scrapy.http.Response):
url = 'http://dev.soeasysdk.com/productProfit/issueCount2.do'
cookies = {
'name': 'joe@stackoverflow.com',
'JSESSIONID': '...',
}
return [FormRequest(
url=url,
cookies=cookies,
meta={'cookiejar': response.meta['cookiejar']},
method='POST',
headers=self.headers,
formdata={
'app_name': '',
'begin_date': str(self.start_date),
'end_date': str(self.start_date),
},
callback=self.parse_page,
dont_filter=True
)]
# and here is the console log
DEBUG [19-10-21 14:47:54] scrapy.downloadermiddlewares.redirect _redirect :43 Redirecting (302) to <GET *************> from <POST *************>
# redirect from expected url to login page, as I think and test in post man and shell, this happened when giving wrong cookies or without cookies
Но когдаЯ пробую это в <requests.request()>
и curl
в оболочке с куки, я могу получить прямое содержимое страницы вместо страницы входа.
url = 'http://dev.soeasysdk.com/productProfit/issueCount2.do'
cookies = {
'name': 'joe@stackoverflow.com',
'JSESSIONID': '...',
}
res = requests.request(method='POST', cookies=cookies, url=url)
print(res.cookies)
print(res.content)
print(res.text)
curl -v --cookie "name=joe@stackoverflow.com; JSESSIONID=..." http://dev.soeasysdk.com/productProfit/issueCount2.do
URL-ссылка на запрос формы, доступ разрешен при входе в систему.
Спасибо за любую помощь!