我打算登录该website与scrapy蜘蛛。登录页面是一个GET请求方法
正如你所看到的,这是一个GET方法并没有为id和passeword显示任何属性。
但在HTML代码中,有一个环节,它表示POST方法method="post"
(当写在我的浏览器的地址栏中它不工作)。但是,当我登录时,有出现在浏览器控制台的网络不使用POST文件。
怎么办呢?
有实际上是在网络日志中的POST请求,但你必须启用“坚持日志”(“保存者LES journaux”):此POST请求发出这会导致在日志中没有明确该设置重定向。
有一点要记住的是,你们需要获取CSRF令牌。下面是如何使用scrapy外壳登录一个简单的例子:
scrapy shell https://www.paris-turf.com/
然后运行以下命令:
from scrapy import FormRequest
# GET the login form fragment.
fetch('https://www.paris-turf.com/compte/login')
# Grab the CSRF token.
token = response.css('[name="_csrf_token"]::attr(value)').get()
# Login. This issues a redirect.
fetch(FormRequest('https://www.paris-turf.com/compte/login_check', formdata={'_username': '[email protected]', '_password': 'yourpassword', '_csrf_token': token}))
# Get the logged in username.
response.css('.media-heading .text-italic::text').get()