发布时间:2019-08-19 09:22:29编辑:auto阅读(1869)
python2
爬虫:从网页上采取数据
爬虫模块:urllib,urllib2,re,bs4,requests,scrapy,xlml
1.urllib
2.request
3.bs4
4.正则re
5种数据类型
(1)数字Number
(2)字符串String
(3)列表List[] 中文在可迭代对象就是unicode对象
(4)元组Tuple()
(5)字典Set{}
爬虫思路:
1.静态 urlopen打开网页------获取源码read
2.requests(模块) get/post请求----获取源码 text()方法 content()方法(建议)
3.bs4 能够解析HTML和XML
#-- coding:utf-8 --
from bs4 import BeautifulSoup
#1
#html="<div>2018.1.8 14:03</div>"
#soup=BeautifulSoup(html,'html.parser') #解析网页
#print soup.div
#2从文件中读取
html=''
soup=BeautifulSoup(open('index.html'),'html.parser')
print soup.prettify()
4.获取所需信息
上一篇: python 安装pip和Django
下一篇: OpenStack Keystone V
48876
47941
38721
35864
30288
27044
26075
20911
20714
19076
512°
612°
614°
618°
594°
579°
645°
718°
836°
939°