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.获取所需信息
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦