欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python爬取中国票房网所有电影片名和演员名字,爬取齐鲁网大陆所有电视剧名称...

发布时间:2023/12/16 python 49 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Python爬取中国票房网所有电影片名和演员名字,爬取齐鲁网大陆所有电视剧名称... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

爬取CBO中国票房网所有电影片名和演员名字

# -*- coding: utf-8 -*- # 爬取CBO中国票房网所有电影片名 import json import requests import timewith open("moviename.txt", 'a') as fh:for pn in range(1,320):url = 'http://www.cbooo.cn/Mdata/getMdata_movie?area=50&type=0&year=0&initial=%E5%85%A8%E9%83%A8&pIndex=' + str(pn)print(url)time.sleep(2)try:result = requests.get(url).textjresult = json.loads(result)movices = jresult.get('pData')for movie in movices:moviename = movie.get('MovieName')print(moviename)fh.write(moviename + "\n")except:print(''+ str(pn) + '失败!')# 爬取CBO中国票房网所有演员 import json import requests import timewith open("moviestar.txt", 'a') as fh:for pn in range(1,2665):url = 'http://www.cbooo.cn/Mdata/getMdate_pList?area=50&type=0&year=0&initial=%E5%85%A8%E9%83%A8&pIndex=' + str(pn)print(url)time.sleep(2)try:result = requests.get(url).textjresult = json.loads(result)movices = jresult.get('pData')for movie in movices:moviename = movie.get('cnName')print(moviename)fh.write(moviename + "\n")except:print(''+ str(pn) + '失败!')

 

爬取电视剧名称

# -*- coding: utf-8 -*- # 爬取所有电视剧名称 # 来源:齐鲁电影网from bs4 import BeautifulSoup import urllib url = "http://www.qilumovie.com/filmclass-txt/9.html" html = urllib.request.urlopen(url).read() htmldecode = html.decode("gbk") #重点关注 soup = BeautifulSoup(htmldecode,"lxml") body = soup.body maplist = body.find_all("li")with open("tvplay.txt",'a') as fh:for tvl in maplist:tv = tvl.a.textprint(tv)fh.write(tv + '\n')

 

 

如有错误,还请大侠指教一二!

 

总结

以上是生活随笔为你收集整理的Python爬取中国票房网所有电影片名和演员名字,爬取齐鲁网大陆所有电视剧名称...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。