Python Requests方法模拟登陆豆瓣FM不成功,pythonrequests,想用requests抓取
Python Requests方法模拟登陆豆瓣FM不成功,pythonrequests,想用requests抓取
想用requests抓取一些豆瓣FM上的东西,模拟登陆失败。代码如下:
#!/usr/bin/pythonimport requestsfrom subprocess import Popen# -- Login Start --postUrl='http://douban.fm/j/misc/login_form'hostUrl='http://douban.fm/'user_agent='Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0'headers={ 'User-Agent':user_agent, 'Connection':'keep-alive', 'Referer': hostUrl}s=requests.Session()s.get(hostUrl,headers=headers)#Get userName and passworduserName=raw_input('Enter your userName:')password=raw_input('Enter your password:')#Get captchaprint 'Get captcha...'rC_id=s.get('http://douban.fm/j/new_captcha',headers=headers)captcha_id=rC_id.text.strip('"')captcha=s.get('http://douban.fm/misc/captcha?size=m&id='+captcha_id,headers=headers)print 'Writing...'f=file('captcha.jpg','wb')f.write(captcha.content)f.close()print 'Open picture...'Popen('captcha.jpg', shell=True)userInput=raw_input('Enter the captcha:')#Post loginformpayload={ 'source':'radio', 'alias': userName, 'form_password': password, 'captcha_solution': userInput, 'captcha_id': captcha_id, 'task': 'sync_channel_list' }r=s.post(postUrl,data=payload,headers=headers)r.raise_for_status() #check status code# -- Login End --
如果成功登陆的话,post过去登陆表单之后服务器会返回用户信息。但是现在print r.text出来的是网页。
我是来歪楼的……
因为网页登陆每次都惨遭验证码,所以还没想过自动登录豆瓣…
会觉得用API靠谱些,你说呢
我感覺你給的那個url, 在網頁上都沒辦法登錄.
嘗試下用http://douban.com/accounts/login來模擬登錄, 然後分享session.
更簡單點, 用官方API
豆瓣API V2
豆瓣 API 参考手册
编橙之家文章,
相关内容
- Python Django利用dwebsocket实现后台数据 实时更新到网页前
- Python有SQL中group by推导吗,pythongroup,现查询基于mongoen
- Python golang中msgpack array序列化问题求指导,golangmsgpack
- Python正则表达式value值处理问题,python正则表达式,初学
- 求Pycharm打包Python脚本方法,pycharmpython,求助,目的是想
- 想实现mysql中的单个参数过滤任务应该怎么写?,mysq
- 关于安装Python Flask-MySQLdb的问题,,在mac上安装使用pip
- Python能做到文件跟踪吗?用什么方法实现,python能做到
- 求Pyqt 函数threading.Thread,print()阻塞解决方法,,我现在
- 想用Python与个判断Zip压缩是否成功的脚本求思路,pyt
评论关闭