首页 > 解决方案 > 使用 Scrapy + Python 使用未知令牌登录

问题描述

我正在尝试使用 Scrapy 向以下网页发出登录请求https://www.greatbuyproducts.com/scs/checkout.ssp?is=login&login=T&fragment=login-register#login-register 我在处理此网页的参数时遇到问题,因为我无法找到令牌,也许我必须生成它,但我不确定

这是我到目前为止的代码,问题是“令牌”部分应该在哪里。

class GreatBuy(scrapy.Spider):
name = "greatbuy"
start_urls = [
    'https://www.greatbuyproducts.com/scs/checkout.ssp?is=login&login=T&fragment=login-register#login-register']

def parse(self, response):
    token =  # I don't know how to get it
    yield scrapy.FormRequest('https://www.greatbuyproducts.com/scs/services/Account.Login.Service.ss?n=2&c=5237170', formdata={'''the token''', 'email': 'my@email.com', 'password': 'mypass', 'send': ''}, callback=self.starscraper)

    def startscraper(self, response):
        yield scrapy.Response('https://www.greatbuyproducts.com/', callback=self.verifylogin)

    def verifylogin(self, response):
        print(response.text)

我注意到查询字符串参数没有改变,我可以在这里使用它们吗?

** 我注意到查询字符串参数没有改变,我可以在这里使用它们吗? **

标签: pythonweb-scrapingscrapy

解决方案


推荐阅读