python
来源:互联网 发布:万达成本优化流程图 编辑:程序博客网 时间:2024/06/05 15:19
偶尔看到一个抓取linkedin数据py代码,真是简单,发请求,只需要两句话
import request
request.get(url)
牛啊,这在别的语言至少10行啊。
解析html,etree,直接扫dom节点取数据,这是方便。看一段登录的代码:
def login(laccount, lpassword):
""" 根据账号密码登录linkedin """
s = requests.Session()
r = s.get('https://www.linkedin.com/uas/login')
tree = etree.HTML(r.content)
loginCsrfParam = ''.join(tree.xpath('//input[@id="loginCsrfParam-login"]/@value'))
csrfToken = ''.join(tree.xpath('//input[@id="csrfToken-login"]/@value'))
sourceAlias = ''.join(tree.xpath('//input[@id="sourceAlias-login"]/@value'))
isJsEnabled = ''.join(tree.xpath('//input[@name="isJsEnabled"]/@value'))
source_app = ''.join(tree.xpath('//input[@name="source_app"]/@value'))
tryCount = ''.join(tree.xpath('//input[@id="tryCount"]/@value'))
clickedSuggestion = ''.join(tree.xpath('//input[@id="clickedSuggestion"]/@value'))
signin = ''.join(tree.xpath('//input[@name="signin"]/@value'))
session_redirect = ''.join(tree.xpath('//input[@name="session_redirect"]/@value'))
trk = ''.join(tree.xpath('//input[@name="trk"]/@value'))
fromEmail = ''.join(tree.xpath('//input[@name="fromEmail"]/@value'))
payload = {
'isJsEnabled': isJsEnabled,
'source_app': source_app,
'tryCount': tryCount,
'clickedSuggestion': clickedSuggestion,
'session_key': laccount,
'session_password': lpassword,
'signin': signin,
'session_redirect': session_redirect,
'trk': trk,
'loginCsrfParam': loginCsrfParam,
'fromEmail': fromEmail,
'csrfToken': csrfToken,
'sourceAlias': sourceAlias
}
s.post('https://www.linkedin.com/uas/login-submit', data=payload)
return s
学习用python,太强大了,一顶十啊
- Python
- Python
- Python
- python
- Python
- PYTHON
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- Python
- python
- Python
- RabbitMQ 学习笔记(五):Topics
- 面试题:合并两个有序的链表
- SQL SERVER 查询、删除重复数据
- Hibernate常用注解
- [NOIp复习计划]:贪心
- python
- java语言发送邮件
- PHP的性能优化
- vim多行注释与取消
- Android 之json解析
- java死锁解析
- ng serve报错 Cannot find module 'webpack/lib/node/NodeTemplatePlugin'
- 你是不是经常套现~判断你的消费是否有积分的方法
- J2EE for Intellij Idea Hibernate开发实例