Python网络爬虫实习报告.docxVIP

  • 134
  • 0
  • 约6.82千字
  • 约 19页
  • 2021-09-10 发布于天津
  • 举报
Python 网络爬虫实习报告 Python网络爬虫实习(报告) Python网络爬虫实习(报告) -i -i - 目录 TOC \o 1-5 \h \z 一、 选题背景 -2 - 二、 爬虫原理 -2 - \o Current Document 三、 爬虫历史和分类 -2 - \o Current Document 四、 常用爬虫框架比较 -2 - \o Current Document 五、 数据爬取实战(豆瓣网爬取电影数据) -3 - 1分析网页 3- 2爬取数据 3- 3数据整理、转换 -4- 4数据保存、展示 -9 - 5技术难点关键点 -10 - 六、 总结 -13 - Python网络爬虫实习(报告) Python网络爬虫实习(报告) - - PAGE # - 选题背景 爬虫原理 三、 爬虫历史和分类 四、 常用爬虫框架比较 Scrapy框架:Scrapy框架是一套比较成熟的Python爬虫框架,是使用 Python开发的快速、高层次的信息爬取框架,可以高效的爬取 web页面并提 取出结构化数据。Scrapy应用范围很广,爬虫开发、数据挖掘、 数据监测、 自动化测试等。 Crawley框架:Crawley也是Python开发出的爬虫框架,该框架致力于 改变人们从互联网中提取数据的方式。 Portia框架:Portia框架是一款允许没有任何编程基础的用户可视化 地爬取网 页的爬虫框架。 newspaper框架:newspaper框架是一个用来提取新闻、文章以及内容 分析 的Python爬虫框架。 Python-goose框架:Python-goose框架可提取的信息包括: v 1 >文章 主体 内容;v2>文章主要图片;v3>文章中嵌入的任heYoutube/Vimeo视 频;v 4 >元描述;v 5 >元标签 五、数据爬取实战(豆瓣网爬取电影数据) 1分析网页 #获取html源代码 def __getHtml(): data =[] pageNum = 1 pageSize = 0 try: while (pageSize = 125): # headers = {User-Age nt:Mozilla/5.0 (Win dowsNT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11, # Referer:No ne # 注意如果依然不能抓取的话,这里 可以设置抓取网站的 host # } ope ner = urllib.request?build_ope ner() ope ner.addheaders = [headers] url = /top250?start= + str(pageSize) + filter= + str(pageNum) # data[html%s % i ]=urllib .request .u rlope n( url) .read() ?decode(utf-8) data.appe n d(urllib.request.urlope n( url).read().decode(utf- 8)) pageSize += 25 pageNum += 1 prin t(pageSize, pageNum) except Excepti on as e: raise e return data 2爬取数据 def __getData(html): title = [] #电影标题 #rati ng_num = [] # 评分 range_num = [] # 排名 #rati n g_people_ num = [] # 评价人数 movie_author = [] # 导演 data = {} # bs4 解析 html soup = BeautifulSoup(html, html.parser) for li in soup.fi nd(ol, attrs 二{class: grid_view}).fi nd_all(li): title.appe n d(li.fi n d(spa n, class_=title).text) #rati ng_nu m. appe n d(li ?fi n d(div, Python网络爬虫实习(报告) Python网络爬虫实习(报告) - - PAGE # - Python网络爬虫实习(报告) Python网络爬虫实习(报告) ==210): ==210): - PAGE # - class_=star)?fi n d(spa n, class_=rat ing_nu m)

文档评论(0)

1亿VIP精品文档

相关文档