神剑山庄资源网 Design By www.hcban.com

Python2.7Mac OS

抓取的是电影天堂里面最新电影的页面。链接地址: http://www.dytt8.net/html/gndy/dyzz/index.html

获取页面的中电影详情页链接

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>.*"25" align="center" bgcolor="#F4FAE2"> ',re.S)
 items = re.findall(pattern,conent) 
 
 str = ''.join(items)
 pattern = re.compile ('<a href="(.*" class="ulink">(.*"htmlcode">
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>(.*""
  # 截取名称
  movieName = movieName[movieName.find("《") + 3:movieName.find("》")]
 else:
  movieName = ""

 print("电影名称: " + movieName.strip())

 movieContent = re.findall(r'<div class="co_content8">(.*""

 print("电影发布时间: " + movieDate[-10:])

 pattern = re.compile('<br /><br />(.*"<br />","")

  # 根据 ◎ 符号拆分

  movieInfo = movieInfo.split('◎')

 else:
  movieInfo = ""

 print("电影基础信息: ")

 for item in movieInfo:
  print(item)


 # 电影海报
 pattern = re.compile('<img.*"(.*".*""
 
 print("电影海报: " + movieImg)

 pattern = re.compile('<td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(.*">.*""

 print("电影下载地址:" + movieDownUrl + "")

 print("------------------------------------------------\n\n\n")

执行抓取

if __name__=='__main__':

  print("开始抓取电影数据");
 
  queryMovieList()
  print(len(movieUrls))

  queryMovieInfo(movieUrls)
  print("结束抓取电影数据")

总结

学好正则表达式很重要,很重要,很重要!!!! Python的语法好有感觉, 对比Java …

标签:
Python,电影天堂

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“Python抓取电影天堂电影信息的代码”

暂无Python抓取电影天堂电影信息的代码的评论...

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。