首页 > 其他 > 详细

爬虫基本 xpath bs mongo request

时间:2021-01-03 19:14:16      阅读:37      评论:0      收藏:0      [点我收藏+]

http://httpbin.org/get
模拟请求方式
django解析json数据
dic=json.loads(request.body.decode())

data= urlcode

json=

 

.text 文本默认utf8 保存 w
.content 字符串 wb
request.history 重定向
不重定向
r = requests.get(‘http://github.com‘, allow_redirects=False)


r.iter_content()

response=requests.get(‘http://httpbin.org/get‘)
res1=json.loads(response.text) #太麻烦
res2=response.json() #直接获取json数据
print(res1==res2)

re.complie("guize",res.text)

re.findall(‘name="authenticity_token" value="(.*?)"‘,res.text,re.S) .代表所有符
号re.S ,包括换行符 ()优先返回findall


r=re.complie(‘guize‘,re.S)
r.finditer(res.text)
(?P<mingzi>.*?)

 

ThreadPoolExecutor.submit()


cookies=res.cookies.get_dicct() request.post("",data=,header=,cokkies=)


session=request.session() 当做request请求,所有请求自带cokkies


1.下载:pip install lxml
2.导包:from lxml import etree

3.将html文档或者xml文档转换成一个etree对象,然后调用对象中的方法查找指定的节点

  2.1 本地文件:tree = etree.parse(文件名)
tree.xpath("xpath表达式")

  2.2 网络数据:tree = etree.HTML(网页内容字符串)
tree.xpath("xpath表达式")

//全局找 属性前@


text 里面所有的文本
string 标签里套标签 none

soup.prettify() html规范化输出

爬虫基本 xpath bs mongo request

原文:https://www.cnblogs.com/dpython/p/14226428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!