Python抓取電影天堂電影信息的代碼
Python2.7Mac OS
抓取的是電影天堂里面最新電影的頁(yè)面。鏈接地址: http://www.dytt8.net/html/gndy/dyzz/index.html
獲取頁(yè)面的中電影詳情頁(yè)鏈接
import urllib2
import os
import re
import string
# 電影URL集合
movieUrls = []
# 獲取電影列表
def queryMovieList():
url = 'http://www.dytt8.net/html/gndy/dyzz/index.html'
conent = urllib2.urlopen(url)
conent = conent.read()
conent = conent.decode('gb2312','ignore').encode('utf-8','ignore')
pattern = re.compile ('<div class="title_all"><h1><font color=#008800>.*?</a>></font></h1></div>'+
'(.*?)<td height="25" align="center" bgcolor="#F4FAE2"> ',re.S)
items = re.findall(pattern,conent)
str = ''.join(items)
pattern = re.compile ('<a href="(.*?)" class="ulink">(.*?)</a>.*?<td colspan.*?>(.*?)</td>',re.S)
news = re.findall(pattern, str)
for j in news:
movieUrls.append('http://www.dytt8.net'+j[0])
抓取詳情頁(yè)中的電影數(shù)據(jù)
def queryMovieInfo(movieUrls):
for index, item in enumerate(movieUrls):
print('電影URL: ' + item)
conent = urllib2.urlopen(item)
conent = conent.read()
conent = conent.decode('gb2312','ignore').encode('utf-8','ignore')
movieName = re.findall(r'<div class="title_all"><h1><font color=#07519a>(.*?)</font></h1></div>', conent, re.S)
if (len(movieName) > 0):
movieName = movieName[0] + ""
# 截取名稱
movieName = movieName[movieName.find("《") + 3:movieName.find("》")]
else:
movieName = ""
print("電影名稱: " + movieName.strip())
movieContent = re.findall(r'<div class="co_content8">(.*?)</tbody>',conent , re.S)
pattern = re.compile('<ul>(.*?)<tr>', re.S)
movieDate = re.findall(pattern,movieContent[0])
if (len(movieDate) > 0):
movieDate = movieDate[0].strip() + ''
else:
movieDate = ""
print("電影發(fā)布時(shí)間: " + movieDate[-10:])
pattern = re.compile('<br /><br />(.*?)<br /><br /><img')
movieInfo = re.findall(pattern, movieContent[0])
if (len(movieInfo) > 0):
movieInfo = movieInfo[0]+''
# 刪除<br />標(biāo)簽
movieInfo = movieInfo.replace("<br />","")
# 根據(jù) ◎ 符號(hào)拆分
movieInfo = movieInfo.split('◎')
else:
movieInfo = ""
print("電影基礎(chǔ)信息: ")
for item in movieInfo:
print(item)
# 電影海報(bào)
pattern = re.compile('<img.*? src="(.*?)".*? />', re.S)
movieImg = re.findall(pattern,movieContent[0])
if (len(movieImg) > 0):
movieImg = movieImg[0]
else:
movieImg = ""
print("電影海報(bào): " + movieImg)
pattern = re.compile('<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(.*?)">.*?</a></td>', re.S)
movieDownUrl = re.findall(pattern,movieContent[0])
if (len(movieDownUrl) > 0):
movieDownUrl = movieDownUrl[0]
else:
movieDownUrl = ""
print("電影下載地址:" + movieDownUrl + "")
print("------------------------------------------------\n\n\n")
執(zhí)行抓取
if __name__=='__main__':
print("開(kāi)始抓取電影數(shù)據(jù)");
queryMovieList()
print(len(movieUrls))
queryMovieInfo(movieUrls)
print("結(jié)束抓取電影數(shù)據(jù)")
總結(jié)
學(xué)好正則表達(dá)式很重要,很重要,很重要!!!! Python的語(yǔ)法好有感覺(jué), 對(duì)比Java …
- 使用Python多線程爬蟲(chóng)爬取電影天堂資源
- 基于python實(shí)現(xiàn)的抓取騰訊視頻所有電影的爬蟲(chóng)
- 編寫Python爬蟲(chóng)抓取豆瓣電影TOP100及用戶頭像的方法
- python實(shí)現(xiàn)去除下載電影和電視劇文件名中的多余字符的方法
- python實(shí)現(xiàn)根據(jù)用戶輸入從電影網(wǎng)站獲取影片信息的方法
- python正則表達(dá)式爬取貓眼電影top100
- 使用python實(shí)現(xiàn)抓取騰訊視頻所有電影的爬蟲(chóng)
- python使用requests模塊實(shí)現(xiàn)爬取電影天堂最新電影信息
- Python爬取APP下載鏈接的實(shí)現(xiàn)方法
- Python3.6實(shí)現(xiàn)根據(jù)電影名稱(支持電視劇名稱),獲取下載鏈接的方法
相關(guān)文章
pyshp創(chuàng)建shp點(diǎn)文件的方法
今天小編就為大家分享一篇pyshp創(chuàng)建shp點(diǎn)文件的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
python 正則表達(dá)式如何實(shí)現(xiàn)重疊匹配
這篇文章主要介紹了python 正則表達(dá)式如何實(shí)現(xiàn)重疊匹配,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
Python GUI編程學(xué)習(xí)筆記之tkinter界面布局顯示詳解
這篇文章主要介紹了Python GUI編程學(xué)習(xí)筆記之tkinter界面布局顯示,結(jié)合實(shí)例形式分析了Python GUI編程中tkinter界面布局顯示的相關(guān)操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-03-03
python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作
這篇文章主要介紹了python 讀txt文件,按‘,’分割每行數(shù)據(jù)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07
Python實(shí)現(xiàn)aes加密解密多種方法解析
這篇文章主要介紹了Python實(shí)現(xiàn)aes加密解密多種方法解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
一行python實(shí)現(xiàn)樹(shù)形結(jié)構(gòu)的方法
今天小編就為大家分享一篇一行python實(shí)現(xiàn)樹(shù)形結(jié)構(gòu)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08
python實(shí)現(xiàn)tail實(shí)時(shí)查看服務(wù)器日志示例
今天小編就為大家分享一篇python實(shí)現(xiàn)tail實(shí)時(shí)查看服務(wù)器日志示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12

