Python网络爬虫实习报告总结归纳.docx

上传人:scccc 文档编号:12568785 上传时间:2021-12-04 格式:DOCX 页数:12 大小:12.38KB
返回 下载 相关 举报
Python网络爬虫实习报告总结归纳.docx_第1页
第1页 / 共12页
Python网络爬虫实习报告总结归纳.docx_第2页
第2页 / 共12页
Python网络爬虫实习报告总结归纳.docx_第3页
第3页 / 共12页
Python网络爬虫实习报告总结归纳.docx_第4页
第4页 / 共12页
Python网络爬虫实习报告总结归纳.docx_第5页
第5页 / 共12页
亲,该文档总共12页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《Python网络爬虫实习报告总结归纳.docx》由会员分享,可在线阅读,更多相关《Python网络爬虫实习报告总结归纳.docx(12页珍藏版)》请在三一文库上搜索。

1、Python 网络爬虫实习报告目录选题背景二、爬虫原理三、爬 虫历史和分类四、常 用爬虫框架比较Scrapy 框架: Scrapy 框架是一套比较成熟的 Python 爬虫框架,是使用Python开发的快速、高层次的信息爬取框架,可以高效的爬取 web页 面并提取出结构化数据。 Scrapy 应用范围很广, 爬虫开发、 数据挖掘、 数据监测、自动化测试等。Crawley 框架: Crawley 也是 Python 开发出的爬虫框架, 该框架致力于 改变人们从互联网中提取数据的方式。Portia 框架: Portia 框架是一款允许没有任何编程基础的用户可视化 地爬取网页的爬虫框架。newspa

2、per框架:newspaper框架是一个用来提取新闻、文章以及内容 分析的 Python 爬虫框架。Python-goose 框架: Python-goose 框架可提取的信息包括: <1>文章 主体内容 ;<2>文章主要图片 ;<3>文章中嵌入的任 heYoutube/Vimeo 视 频;<4>元描述 ;<5>元标签五、数据爬取实战(豆瓣网爬取电影数据)1分析网页#获取html源代码def _getHtml():data =pageNum = 1pageSize = 0try:while (pageSize <= 125):注

3、意如果依然不能抓取的话,这里# 'Referer':No ne #可以设置抓取网站的host# # = headerspageNum)pageSize += 25pageNum += 1prin t(pageSize, pageNum)except Excepti on as e:raise e return data2爬取数据 def _getData(html):title = #电影标题#rati ng_num = # 评分range_num = # 排名#rati ng_people_ num = # 评价人数movie_author = # 导演data = # bs

4、4 解析 htmlsoup = BeautifulSoup(html,"")for li in ("ol", attrs二'class':'grid_view').fi nd_all("li"):("spa n", class_="title").text)#("div", class_='star').fi nd("spa n",class_='rat ing_nu m').text)(&q

5、uot;div", class_='pic').fi nd("em").text)#spa ns = ("div", class_='star').fi nd_all("spa n")#for x in ran ge(le n( spa ns):# if x <= 2:# pass# else:# (spa nsx.stri ng-le n(spa nsx.stri ng):-3) str = ("div", class_='bd').fi nd(&q

6、uot;p", class_='').()in dex =("主")if (in dex = -1):in dex =(".")=210):prin t("div", class_='pic').fi nd("em").text)if("div",class_='pic').fi nd("em").textin dex = 60# prin t("aaa")# prin t(str4:i ndex)

7、(str4:i ndex)data'title' = title#data'rati ng_nu m' = rati ng_numdata'ra nge_nu m' = range_num#data'rati ng_people_ nu m' = rati ng_people_ num data'movie_autho门=movie_authorreturn data3数据整理、转换 def _getMovies(data):("vhtml>")("<head><met

8、a charset二'UTF-8'><title> In sert titlehere</title>v/head>")("vbody>")("<h1>爬取豆瓣电影</h1>")("<h4>作者:刘文斌</h4>")("<h4>时间:” + nowtime + "</h4>")("<hr>")("vtable width二&#

9、39;800px' border二'1' alig n=ce nter>")("<thead>")("<tr>")("<th><fo nt size二'5' color=gree n>电影 v/fon t></th>")#("<th width='50px'xfo nt size='5' color=gree n>评分v/fon t></th>

10、")("<th width='50px'><fo nt size='5' color=gree n>排名</fon t></th>")#("<th width='100px'xfont size='5' color=green> 评价人数v/fon t></th>")("<th><fo nt size='5' color=gree n>导演 </fo

11、 nt></th>")("v/tr>")("v/thead>")("vtbody>")for data in datas:for i in ran ge(0, 25):("<tr>")("<tdstyle二'color:ora nge;text-alig n:ce nter'>%s</td>" % data'title'i)#("<tdstyle='color

12、:blue;text-align:center'>%s</td>" % data'rati ng_nu m'i)("<tdstyle='color:red;text-align:center'>%s</td>" % data'ra nge_nu m'i)#("<tdstyle='color:blue;text-align:center'>%s</td>" % data'rati ng_people _

13、nu m'i)("<tdstyle二'color:black;text-align:center'>%s</td>" % data'movie_author'i)("</tr>")("v/tbody>")("v/thead>")("v/table>")("</body>")("</html>")()if _name_ = '_mai

14、n_':datas =htmls = _getHtml()for i in ran ge(le n(htmls):data = _getData(htmlsi)(data)_getMovies(datas)4数据保存、展示结果如后图所示:5技术难点关键点数据爬取实战(搜房网爬取房屋数据)from bs4 import BeautifulSoup import requests rep =()="gb2312"#设置编码方式html =soup = BeautifulSoup(html, ” )f = open(,'w' , encoding =

15、9;utf-8')("<html>")("<head><meta charset二'UTF-8'><title> In sert titlehere</title>v/head>" )("vbody>")("<center><h1> 新房成交 TOP3</h1>v/center>")("<table border='1px' width二'

16、1000px' height二'800px'alig n=ce nter><tr>" )("<th><h2> 房址 v/h2>v/th>")("<th><h2> 成交量 v/h2>v/th>")("<th><h2> 均价 v/h2>v/th>v/tr>")for li in ("ul" , class_ ="ul02" ).find

17、_all( "li"):name=( "div" , class_ ="pbtext" ).find("p" ).textchengjiaoliang=("span" , class_ ="red-f3" ).texttry : junjia=( "div" , class_ 二"ohter" ).find( "p" , class_ 二"gray-9" )#.('? O',

18、9;平方米')except Exception as e:junjia=( "div" , class_ ="gray-9" )#.('?O',' 平方米')("<tr><td alig n=cen ter><fo nt size二'5px'color二red>%s</fo nt>v/td>"% n ame)("<td alig n=ce nter>vfo nt size='5px'color二blue>%s</fo nt>v/td>"% che ngjiaolia ng)("<td alig n=ce nter>vfo nt size='5px'color二gree n> %s</fo nt>v/td>v/tr>"% junjia)print (name)("</table>")("</body>")六、总结教师评语:成绩:指导教师:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1