豆瓣网的模拟登陆
想要模拟登录请求,并更改自己的签名。但是报错了,原因是缺少了参数,但表单数据貌似没错,希望大神指教一下小白。class DoubanSpiderSpider(scrapy.Spider):
name = 'douban_spider'
allowed_domains = ["douban.com"]
start_urls = ["https://www.douban.com/"]
def start_requests(self):
url = 'https://www.douban.com/'
formdata = {"ck":"","name":"15013011722","password":"1097745638a","remember":"false","ticket":""}
request = scrapy.FormRequest(url,formdata=formdata,callback=self.second_request)
self.fp = open('123.html','w',encoding='UTF-8')
yield request
def second_request(self,response):
self.fp.write(response.text)
url = 'https://www.douban.com/people/217931200/'
ck = response.xpath("//form[@name='edit_sign']//div//input[@name='ck']/@value").extract()
print(ck)
formdata = {
"ck":ck,
"signature":"123456"
}
request = scrapy.FormRequest(url,formdata=formdata,callback=self.parse)
yield request
收藏 建议你用selenium
不知道selenium怎么用?
idle输入help(selenium) xiaosi4081 发表于 2020-6-16 07:53
建议你用selenium
不知道selenium怎么用?
谢谢你。虽然可以用selenium,但还是挺想知道会出现参数缺失的情况的原因的。。。{:10_266:} 豆瓣模拟登录可以参考我之前开源的代码:https://github.com/CharlesPikachu/DecryptLogin 好的
页:
[1]