ITPub博客

首页 > IT职业 > IT生活 > python爬虫思路

python爬虫思路

IT生活 作者:THUNDER2 时间:2021-09-09 09:21:36 0 删除 编辑

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="

2018.1.8 14:03
"
#soup=BeautifulSoup(html,'html.parser') #解析网页
#print soup.div
#2从文件中读取
html=''
soup=BeautifulSoup(open('index.html'),'html.parser')
print soup.prettify()
4.获取所需信息

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3566/viewspace-2802607/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-30

  • 博文量
    74
  • 访问量
    519