首页 > 编程知识 正文

python 可视化界面,python爬取网页视频的代码

时间:2023-05-05 10:38:10 阅读:146341 作者:1600

另一方面,登上新闻获取的网站请参照代码部分的url_list列表。 总共有三个网站。

importrequestsfromlxmlimportetreeheaders={ ' user-agent ' : ' Mozilla/5.0 (Linux; 安卓6.0 nexus 5构建/xsd HLB (apple WebKit/537.36 ) khtml,like Gecko ) chrome/83.0.4103.106 mobile safari/537.36 } URL SCM=0.0.0.0SPM=smpc.subject.column-1.1.162762619935 jqrji 3x ',' https://www.Sohu.com/a/47987571717 SCM=0.0.0.0SPM=smpc.subject.column-3.7.1627628959142 K9 lwxvn ', ' https://www.Sohu.com/a/480084797 _ } SPM=smpc.subject.slider-1.1.1627626596286 niwehku ' ] def parse _ URL headers (3360 resp=requests.get headers=headers (.content.decode (utf-8 ) )启动请求并调用content方法, 用utf-8方法解码内容html_element=etree.html ) ' a ',encoding='utf-8 ' ) PS=html _ element.XPath (' ) n ' ) #写入文本except: continue #如果获取的内容为空,则f.close(#闭合文本if _ name _==' _ _ main _ ' 3360 for _ rlin _ rrrin 词频统计importjiebaimportnltkimportpandasaspdraw=PD.read _ table (new.txt ), names=['txt']文本raw[:10]raw['temp']=1 #列组forIinrange(len(raw ) ) 3360ifraw.txt ) I=' ' or raw.txt[i]=='来源:魅力湘西官网' : raw.loc[i,' temp']=0 #过滤不需要的信息else: pass raw['temp']=1 # 分组后的合计word _ list=Jie ba.lcut (raw grp.txt [1] )分词SW=list ) (PD.read_table )停止字. txt ',names=[ ] 、 ','?、、、、、##NLTK统计字数ff 字云图frommatplotlibimportpyplotaspltimportwordcloudmyfonnt中文格式cloud obj=word cloud.word cloud (font _ path=my font,widd cloud

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。