爬虫python网络爬虫实习报告-python实习报告

爬虫代理  时间:2021-04-12  阅读:()

Pyth o n网络爬虫实习报告

目录

一、选题背景. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .错误!未定义书签

二、爬虫原理?错误!未定义书签。

三、爬虫历史与分类. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .错误!未定义书签

四、常用爬虫框架比较?错误!未定义书签。

五、数据爬取实战豆瓣网爬取电影数据 . . . . . . . . . .错误!未定义书签

1分析网页?错误!未定义书签。

2爬取数据. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .错误!未定义书签

3数据整理、转换?错误!未定义书签。

4数据保存、展示?错误!未定义书签。

5技术难点关键点?错误!未定义书签。

六、总结. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .错误!未定义书签

选题背景

二、 爬虫原理

三、 爬虫历史与分类

四、 常用爬虫框架比较

Scrap y框架 Sera py框架就是一套比较成熟得Pytho n爬虫框架 就是使用Python开发得快速、高层次得信息爬取框架可以高效得爬取web页面并提取出结构化数据。 S erap y应用范围很广爬虫开发、 数据挖掘、数据监测、 自动化测试等.

Crawle y框架 C r a wley也就是Pytho n开发出得爬虫框架该框架致力于改变人们从互联网中提取数据得方式。

Portia框架 P orti a框架就是一款允许没有任何编程基础得用户可视化地爬取网页得爬虫框架。newspa p e r框架 nc wspape r框架就是一个用来提取新闻、文章以及内容分析得Pyth o n爬虫框架.

Py t ho n-go o se框架 Pyth o n-go o se框架可提取得信息包括 〈1文章主体内容;2文章主要图片 3文章中嵌入得任h eYo utube/Vi meo视频 4〉元描述 〈5〉元标签

五、数据爬取实战豆瓣网爬取电影数据

1分析网页

#获取ht m l源代码

try: ?wh i le(p ageSiz e 〈=125):

#headers= {'U ser—Ag en t' : 'Mozi

1 l a/5、 0(Windows NT 6、 1)Ap p 1 eWeb Ki t/537、 1 1 (KHTML, l ike Gecko)Ch rome/23、 0、 1271、 64 Safari/537>11',

# 'Refe r er':None #注意如果依然不能抓取得话,这里可以设置抓取网站得h ost

#}? #o pener=url l ib、 req ue st、 bui ld_opener()

#opener、 addhea der s= [header s]?ur l="”+st r(pag e Siz e)+ ”&f i lt e r(p ageNum)

#data['h t ml%s%i ]=url 1i b、 re q uest、ur 1 open(ur 1)、 read()、 decode("utf—8")?dat a、 append(url 1 i b、 requ e st、 urlopen(ur 1 )、 read()、d ecode(”ut f—8H))page S i z e+= 25? p age N

um+=1 ?pr int(pageSize,pageNum)excep t E x cepti o n a s e:r ai se eretu r n data

2爬取数据def__getData(html):title= #电影标题 #rati ng_n um=[]#评分? range_num二 口#排名? #rat ing—people_num=[ ] #评价人数movie_author=[] #导演? da t a={}

#b s4解析h t ml?s oup=Beauti f u l Sou p(html,”html、 parser”)?for l i i n sou p、 find(”o I”,a tt rs= {'clas s': 'grid_view'} )、 fin d—al l( "l i"):t it le、 append( l i 、 f i nd("span",cl a ss—二”title”)、 t ext)

#rating_num、 append(l i 、 fin d("d i v” class_='star') 、find(”span",class_='rat ing_nu m')、 t ext)ra n ge—num、 ap pend(l i、 fi n d("di v”,class—='pi c')ffind("emH)、 text )? #spans=l i、 find("d iv” c l as s—='star )' 、 find_a l l (Hsp an") ? #fo rxin ran ge(le n(spans)):

#i fx<=2:? # pass?#e 1 se

# rat ing_peo ple_num、 append(spans[x]、 stri ng[—1e n( s pans[x]、 st rin g):—3])str=l i、 fi n d(”div",cla ss_='b d')、 find(”p",clas s—='')、 text、 lstrip()?in d ex=st r、 find("主")?if(ind ex==—1 ):index=str 、 fin d("、 、 、 ")?prin t (l i 、 fin d(”d i v” c las s_='p i c' ) 、 find(”em")、 t e xt)if(l i 、 find("div”,cl a s s_='pic')、 find(”em”)、 text==210):i n d ex= 60

# p rint("aaa”) #p rint (str[4:i ndex])? movie_author、 append(str[4: i nde x])d a t a['t i tl e'] =titl e

#data['rat ing_num'] =rat i ng_numdat a[/ rang e—nu m]=ra nge_nun?#data[ 'rating_p eo pl e_n um']=r at i n_peopl e_numdata['mov ie_au t ho r']=movie_a u th o rret u rn dat a

3数据整理、转换def—_getMov i e s(da t a):f=ope n('F: 〃 douba n_movi e、 html ', 'w' , e ncodi ng='u tf—8')f 、w rite(" 〈html>”)f、wr i te(”<h e ad><me t a charset二'UTF-8'> 〈title>In sert titlehere</ t it 1 ex/he ad>”) f、wr i te(” 〈b o d y>”)?f、write(” 〈h 1>爬取豆瓣电影v/hl>")f、wri te(”<h4>作者刘文斌〈/h 4>”)f、wr i te(” 〈 h4>时间 "+no wt i me+”v/h 4>”)?f、wri te("<hr>”)f 、w r i te("<t able width='8 OOpx' border二'1 'a 1ign二center>")f 、wr i te(" 〈th e ad>”) f、wr ite("<t r>")?f、write(”<t h><fontsi z e='5'c olor=g reen〉电影</fo nt></th〉 ”)?#f、wr ite(Hvt hwidt h=50pxz><fo nt s i z e='5'c o lor=g r ee n>评分v/font〉 〈/th>")f、wri t e(" 〈th w i d th='50 px'> 〈 f o nt size='5/c ol o r=green>排

名〈/fo nt〉 〈/th>”) #f、wr ite("

〈thwidth='100px'〉 〈 fontsize='5'color=green〉评价人数v/font></t

h>")?f、write(" 〈th> 〈font siz e='5/color=gr e en>导演〈/font〉 v/th>”)f、wr it e(”</tr>")f 、w r i te("</th e ad〉 ”)f>wr ite("<tbod y>”)fordataindatas :?for i inrange(0,

25) :? f、write(” <t r〉 ”)f 、write( "<td styl e='c olor:ora n ge; t ext—al ign:cen t er'

>%s</td〉 ”%d ata ['ti t le'][i] )? #f、wr ite(” <td s ty le='colo r:bl ue te xt—a 1 ign :c e nte 「 〉 sv/t d>" %data[/ r at i n g_num'] [i ] )?f、write("<td sty1e='co lor: red; text—al ign cent er'〉 s</td〉 ”%data['r ange_num] [i])

#f 、 wr i te("vtd style='co 1 or:bl ue;text-al ig n:cen te r'>%s〈/td>”%d a ta[ 'r ating_p e ople_nu m'] [i :)f、write(” 〈 td st y le='col o r:b l ac k;t ext—a l ign:center '〉 s</td>"%d ata[ 'mo vi e—aut h or'] [i ])f 、write(" 〈/tr>") ?f 、wri t e(” 〈/tbody>")

f、write("v/ thead>")?f wri te(”</ table>H)f 、wri t e(”</bo d y>")? f、write( " 〈/h t ml〉 ”)f 、 close()i f__n ame__== _ma i n _:

data s=h tmls=__getH tml ()? for i i n rang e( len(htmls) ) :?dat a=__getData(ht m ls[ i ])?datas、 app end(data)

? —_g e tMovies(datas)

4数据保存、展示

结果如后图所示

硅云香港CN2+BGP云主机仅188元/年起(香港云服务器专区)

硅云怎么样?硅云是一家专业的云服务商,硅云的主营产品包括域名和服务器,其中香港云服务器、香港云虚拟主机是非常受欢迎的产品。硅云香港可用区接入了中国电信CN2 GIA、中国联通直连、中国移动直连、HGC、NTT、COGENT、PCCW在内的数十家优质的全球顶级运营商,是为数不多的多线香港云服务商之一。目前,硅云香港云服务器,CN2+BGP线路,1核1G香港云主机仅188元/年起,域名无需备案,支持个...

老薛主机入门建站月付34/月,年付345元,半价香港VPS主机

老薛主机怎么样?老薛主机这个商家有存在有一些年头。如果没有记错的话,早年老薛主机是做虚拟主机业务的,还算不错在异常激烈的市场中生存到现在,应该算是在众多商家中早期积累到一定的用户群的,主打小众个人网站业务所以能持续到现在。这不,站长看到商家有在进行夏季促销,比如我们很多网友可能有需要的香港vps主机季度及以上可以半价优惠,如果有在选择不同主机商的香港机房的可以看看老薛主机商家的香港vps。点击进入...

小欢互联19元/月起, 即日起至10月底 美国CERA 促销活动 美国/香港八折

小欢互联成立于2019年10月,主打海外高性价比云服务器、CDN和虚拟主机服务。近期上线了自营美国CERA机房高速VPS,进行促销活动,为客户奉上美国/香港八折优惠码:Xxc1mtLB优惠码适用于美国CERA一区/二区以及香港一区/二区优惠时间:即日起至10月底优惠码可无限次使用,且续费同价!官网:https://idc.xh-ws.com购买地址:美国CERA一区:https://idc.xh-...

爬虫代理为你推荐
phpadmin下载免费MP3下载phpadmin下载phpMyAdmin 软件下载地址phpadmin下载phpmyadmin怎么安装啊?可以直接下载安装吗?还需要下载其他数据库吗?上海市浦东新区人民法院民事判决书(2009)浦民三(知)初字第206号资费标准联通所有套餐介绍泉州商标注册泉州本地商标注册要怎么注册?具体流程是什么?tumblr上不去安卓手机版steam打不开是为什么网络u盘有没有网络U盘 5G的 就像真的U盘一样的?就像下载到真U盘一样的 到自己电脑直接复制就可以拉的啊工具条有什么工具条比较好joomla教程有谁能给一份详细的popsub特效教程---------
域名到期查询 cn域名备案 免费顶级域名 免费申请网页 免费名片模板 iis安装教程 镇江联通宽带 商务主机 hostloc 阿里校园 电信主机 能外链的相册 常州联通宽带 广州虚拟主机 cdn网站加速 免费蓝钻 酸酸乳 广东主机托管 hosting24 cx域名 更多