Python网络爬虫实习报告python实习报告.docx

上传人:b****5 文档编号:7716620 上传时间:2023-01-26 格式:DOCX 页数:5 大小:112.17KB
下载 相关 举报
Python网络爬虫实习报告python实习报告.docx_第1页
第1页 / 共5页
Python网络爬虫实习报告python实习报告.docx_第2页
第2页 / 共5页
Python网络爬虫实习报告python实习报告.docx_第3页
第3页 / 共5页
Python网络爬虫实习报告python实习报告.docx_第4页
第4页 / 共5页
Python网络爬虫实习报告python实习报告.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

Python网络爬虫实习报告python实习报告.docx

《Python网络爬虫实习报告python实习报告.docx》由会员分享,可在线阅读,更多相关《Python网络爬虫实习报告python实习报告.docx(5页珍藏版)》请在冰豆网上搜索。

Python网络爬虫实习报告python实习报告.docx

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

Python网络爬虫实习报告

一、

选题背景

二、爬虫原理

三、爬虫历史与分类

四、常用爬虫框架比较

Scrapy框架:

Scrapy框架就是一套比较成熟的Python爬虫框架,就是使用Python开发的快速、高层次的信息爬取框架,可以高效的爬取web页面并提取出结构化数据。

Scrapy应用范围很广,爬虫开发、数据挖掘、数据监测、自动化测试等。

Crawley框架:

Crawley也就是Python开发出的爬虫框架,该框架致力于改变人们从互联网中提取数据的方式。

Portia框架:

Portia框架就是一款允许没有任何编程基础的用户可视化地爬取网页的爬虫框架。

newspaper框架:

newspaper框架就是一个用来提取新闻、文章以及内容分析的Python爬虫框架。

Python-goose框架:

Python-goose框架可提取的信息包括:

<1>文章主体内容;<2>文章主要图片;<3>文章中嵌入的任heYoutube/Vimeo视频;<4>元描述;<5>元标签

五、数据爬取实战(豆瓣网爬取电影数据)

1分析网页

#获取html源代码

def__getHtml():

data=[]

pageNum=1

pageSize=0

try:

while(pageSize<=125):

#headers={'User-Agent':

'Mozilla/5、0(WindowsNT6、1)AppleWebKit/537、11(KHTML,likeGecko)Chrome/23、0、1271、64Safari/537、11',

#'Referer':

None#注意如果依然不能抓取的话,这里可以设置抓取网站的host

#}

#opener=urllib、request、build_opener()

#opener、addheaders=[headers]

url=""+str(pageSize)+"&filter="+str(pageNum)

#data['html%s'%i]=urllib、request、urlopen(url)、read()、decode("utf-8")

data、append(urllib、request、urlopen(url)、read()、decode("utf-8"))

pageSize+=25

pageNum+=1

print(pageSize,pageNum)

exceptExceptionase:

raisee

returndata

2爬取数据

def__getData(html):

title=[]#电影标题

#rating_num=[]#评分

range_num=[]#排名

#rating_people_num=[]#评价人数

movie_author=[]#导演

data={}

#bs4解析html

soup=BeautifulSoup(html,"html、parser")

forliinsoup、find("ol",attrs={'class':

'grid_view'})、find_all("li"):

title、append(li、find("span",class_="title")、text)

#rating_num、append(li、find("div",class_='star')、find("span",class_='rating_num')、text)

range_num、append(li、find("div",class_='pic')、find("em")、text)

#spans=li、find("div",class_='star')、find_all("span")

#forxinrange(len(spans)):

#ifx<=2:

#pass

#else:

#rating_people_num、append(spans[x]、string[-len(spans[x]、string):

-3])

str=li、find("div",class_='bd')、find("p",class_='')、text、lstrip()

index=str、find("主")

if(index==-1):

index=str、find("、、、")

print(li、find("div",class_='pic')、find("em")、text)

if(li、find("div",class_='pic')、find("em")、text==210):

index=60

#print("aaa")

#print(str[4:

index])

movie_author、append(str[4:

index])

data['title']=title

#data['rating_num']=rating_num

data['range_num']=range_num

#data['rating_people_num']=rating_people_num

data['movie_author']=movie_author

returndata

3数据整理、转换

def__getMovies(data):

f=open('F:

//douban_movie、html','w',encoding='utf-8')

f、write("")

f、write("Inserttitlehere")

f、write("")

f、write("

爬取豆瓣电影

")

f、write("

作者:

刘文斌

")

f、write("

时间:

"+nowtime+"

")

f、write("


")

f、write("")

f、write("")

f、write("")

f、write("电影")

#f、write("评分")

f、write("排名")

#f、write("评价人数")

f、write("导演")

f、write("")

f、write("")

f、write("")

fordataindatas:

foriinrange(0,25):

f、write("")

f、write("

orange;text-align:

center'>%s"%data['title'][i])

#f、write("

blue;text-align:

center'>%s"%data['rating_num'][i])

f、write("

red;text-align:

center'>%s"%data['range_num'][i])

#f、write("

blue;text-align:

center'>%s"%data['rating_people_num'][i])

f、write("

black;text-align:

center'>%s"%data['movie_author'][i])

f、write("")

f、write("")

f、write("")

f、write("")

f、write("")

f、write("")

f、close()

if__name__=='__main__':

datas=[]

htmls=__getHtml()

foriinrange(len(htmls)):

data=__getData(htmls[i])

datas、append(data)

__getMovies(datas)

 

4数据保存、展示

结果如后图所示:

5技术难点关键点

数据爬取实战(搜房网爬取房屋数据)

frombs4importBeautifulSoup

importrequests

rep=requests、get('')

rep、encoding="gb2312"#设置编码方式

html=rep、text

soup=BeautifulSoup(html,'html、parser')

f=open('F:

//fang、html','w',encoding='utf-8')

f、write("")

f、write("Inserttitlehere")

f、write("")

f、write("

新房成交TOP3

")

f、write("")

f、write("

房址

")

f、write("

成交量

")

f、write("

均价

")

forliinsoup、find("ul",class_="ul02")、find_all("li"):

name=li、find("div",class_="pbtext")、find("p")、text

chengjiaoliang=li、find("span",class_="red-f3")、text

try:

junjia=li、find("div",class_="ohter")、find("p",class_="gray-9")#、text、replace('�O','平方米')

exceptExceptionase:

junjia=li、find("div",class_="gray-9")#、text、replace('�O','平方米')

f、write("%s"%name)

f、write("%s"%chengjiaoliang)

f、write("%s"%junjia)

print(name)

f、write("")

f、write("")

六、总结

教师评语:

 

成绩:

指导教师:

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

当前位置:首页 > 高等教育 > 理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1