爬虫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数据保存、展示

结果如后图所示

【IT狗】在线ping,在线tcping,路由追踪

IT狗为用户提供 在线ping、在线tcping、在线路由追踪、域名被墙检测、域名被污染检测 等实用工具。【工具地址】https://www.itdog.cn/【工具特色】1、目前同类网站中,在线ping 仅支持1次或少量次数的测试,无法客观的展现目标服务器一段时间的网络状况,IT狗Ping工具可持续的进行一段时间的ping测试,并生成更为直观的网络质量柱状图,让用户更容易掌握服务器在各地区、各线...

ReliableSite怎么样,月付$95美国洛杉矶独立服务器

ReliableSite怎么样?ReliableSite好不好。ReliableSite是一家成立于2006年的老牌美国商家,主要经营美国独立服务器租赁,数据中心位于:洛杉矶、迈阿密、纽约,带宽1Gbps起步,花19美元/月即可升级到10Gbps带宽,月流量150T足够各种业务场景使用,且免费提供20Gbps DDoS防护。当前商家有几款大硬盘美国独服,地点位于美国洛杉矶或纽约机房,机器配置很具有...

VirMach:$27.3/月-E3-1240v1/16GB/1TB/10TB/洛杉矶等多机房

上次部落分享过VirMach提供的End of Life Plans系列的VPS主机,最近他们又发布了DEDICATED MIGRATION SPECIALS产品,并提供6.5-7.5折优惠码,优惠后最低每月27.3美元起。同样的这些机器现在订购,将在2021年9月30日至2022年4月30日之间迁移,目前这些等待迁移机器可以在洛杉矶、达拉斯、亚特兰大、纽约、芝加哥等5个地区机房开设,未来迁移的时...

爬虫代理为你推荐
access数据库修复请问Access数据库修复恢复该怎么办啊,有些页和模块打不开了,也不知道是怎么回事,丢了文件还德国iphone禁售令苹果在中国禁售了?说说看cuteftpCuteFTP的主要功能是什么?360邮箱邮箱地址指的是什么?flashfxp下载求最新无需注册的FlashFXP下载地址结点cuteftp的是cuteftp开放平台企鹅号和腾讯内容开放平台是一样的吗,有什么区别?银花珠树晓来看用黄皮比喻心酸的诗句青岛网通测速网通,联通,长城这三个宽带哪个网速最快?我是青岛的
网络域名注册 赵容 ion wordpress技巧 回程路由 工作站服务器 中国电信测网速 南通服务器 1美金 网游服务器 上海联通宽带测速 网站在线扫描 空间登陆首页 上海电信测速网站 东莞主机托管 lamp兄弟连 攻击服务器 阿里云邮箱个人版 杭州电信 accountsuspended 更多