python 爬虫登录世纪佳缘
来源:互联网 发布:python insert怎么用 编辑:程序博客网 时间:2024/04/27 20:41
python 爬虫登录世纪佳缘
程序运行相关环境:
win7
python2.7.13
python requests包
python beautifulsoup包
代码示例:
# -*- coding: utf-8 -*-import requestsfrom cookielib import LWPCookieJarfrom bs4 import BeautifulSoup as bsimport osimport timeimport jsonimport urllibdef toJson(str): soup = bs(str,"html.parser") tt = {} for inp in soup.form.find_all('input'): if inp.get('name')!=None: tt[inp.get('name')]=inp.get('value') return tts = requests.Session()s.cookies = LWPCookieJar('cookiejar')header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; rv:54.0) Gecko/20100101 Firefox/54.0'}print 'there is no cookie setting'r = s.get("http://login.jiayuan.com/")soup = toJson(r.text)print soup#yourloginname#yourpasswordpayload = {'position': soup['position'], 'channel': soup['channel'], '_s_x_id': soup['_s_x_id'],'m_p_l': soup['m_p_l'], 'ljg_login': soup['ljg_login'], 'name': 'yourloginname', 'password': 'yourpassword'}r = s.post("https://passport.jiayuan.com/dologin.php?pre_url=http://www.jiayuan.com/usercp", data=payload, headers=header)s.cookies.save(ignore_discard=True)# <title>登录成功</title>#print r.textif r.text.count(u'jump'): print "登录成功"
上面的代码只需将用户名和密码修改为自己的就可以了。
PS:该代码的运行过程是通过firefox 的 Tamper Data工具模拟出来的,大家在手动登录世纪佳缘网站时可以使用Tamper Data跟踪登录过程。
阅读全文
0 0
- python 爬虫登录世纪佳缘
- python爬虫含登录
- Python爬虫 - 登录csdn
- python爬虫程序-登录
- Python爬虫 模拟登录
- Python爬虫登录功能
- python爬虫-京东登录
- Python爬虫与模拟登录
- python爬虫之登录豆瓣
- python -- 拉勾网爬虫模拟登录
- python爬虫实践之模拟登录
- python 爬虫 自动登录人人网
- 转载:python爬虫实践之模拟登录
- Python爬虫实现自动登录、签到
- python 爬虫——登录知乎
- python爬虫基础登----网站登录
- Python爬虫之模拟登录总结
- python爬虫:用户名密码登录认证
- HPU16级暑期集训练习(一)
- struct sk_buff与socket
- PAT(Basic Level)_1005_继续(3n+1)猜想
- Fibonacci数列
- Codis proxy error : dial tcp : lookup cnsz22vla888.novalocal on 127.0.1.1:53 : no such host
- python 爬虫登录世纪佳缘
- windows10+cuda7.5+caffe
- 添加水印
- angularjs基本知识学习(1)
- [机器学习入门] 李宏毅机器学习笔记-27(Structured SVM part 2;结构化支持向量机 part 2)
- iOS-UITextField监听输入内容的解决办法
- redis笔记
- java 多线程一
- LintCode 删除链表中的元素