當前位置:
首頁 >
Python爬取中国票房网所有电影片名和演员名字,爬取齐鲁网大陆所有电视剧名称...
發布時間:2023/12/16
31
豆豆
生活随笔
收集整理的這篇文章主要介紹了
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爬取中国票房网所有电影片名和演员名字,爬取齐鲁网大陆所有电视剧名称...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php工程师外派,招聘兼职Php工程师|
- 下一篇: hover和active的区别