xchaoinfo / fuck-login

模拟登录一些知名的网站,为了方便爬取需要登录的网站
5.86k stars 2.02k forks source link

豆瓣获取验证码那里可以get方式直接获取吗,豆瓣好像给我返回了一个假页面 #106

Open zhangxiangqiang opened 6 years ago

zhangxiangqiang commented 6 years ago

豆瓣获取验证码那里可以get方式直接获取吗,豆瓣好像给我返回了一个假页面: 我看代码是先post数据,跳转一个页面再获取验证码,我是直接在https://www.douban.com/,上获取,然后验证码和其数据一起post,但是返回的页面是个人相关信息,不能进入其他页面,里面有什么猫腻吗: 验证码部分代码如下: def get_captcha():

page = s.post("https://www.douban.com/accounts/login", headers=headers, data=data) #用post就可以

url = "https://www.douban.com/"
page = s.get(url, headers=headers)  # 先进入主页,直接获取验证码就不行
tree = etree.HTML(page.text)
href = tree.xpath('//*[@id="captcha_image"]/@src')[0]
img = requests.get(href)
#?id=yuA3OjOTHxIwmpdAGQh0C8rt:en&size=s"
id_obj = re.match(".*id=(.*)&.*", href)
id = id_obj.group(1)
print(href,id)
with open("douban_chaptcha.png", "wb") as f:
    f.write(img.content)
captcha = input("请输入验证码:")
return captcha, id

返回页面: image

iamxuwenjin commented 6 years ago

https://www.douban.com/accounts/login这个应该是个旧版本的登录接口

starryfei commented 6 years ago

豆瓣登录获取验证码可以直接在首页: https://www.douban.com/, 不过有时候不需要验证码,就可以直接登录, post 地址: https://www.douban.com/accounts/login