网址:https://www.endata.com.cn/BoxOffice/MovieStock/movieShow.html?id=661004
使用 requests 爬取上述页面,请求不到完整页面内容,之后尝试使用selenium+webdriver 然后beatifulsoup解析的方式来爬取,查看driver.pagesource 还是没有得到完整的页面。
想爬取这个页面的 电影名称、演员、导演等信息,有没有大神帮助解惑?
网址:https://www.endata.com.cn/BoxOffice/MovieStock/movieShow.html?id=661004
使用 requests 爬取上述页面,请求不到完整页面内容,之后尝试使用selenium+webdriver 然后beatifulsoup解析的方式来爬取,查看driver.pagesource 还是没有得到完整的页面。
想爬取这个页面的 电影名称、演员、导演等信息,有没有大神帮助解惑?
题主使用selenium获得的page_source没有具体内容,是因为网页还没加载出来呢,就开始读取html的page_source了,所以输出来的是未渲染的内容。
只需要简单的sleep两秒,再读取page_source就可以了。
#coding:utf-8
from selenium import webdriver
import time
import re
driver=webdriver.Chrome()#谷歌
driver.get(url='https://www.endata.com.cn/BoxOffice/MovieStock/movieShow.html?id=661004')
time.sleep(2)
html = driver.page_source
title = re.findall('<h3>(.*?)<sub>', html)[0]
print("电影名:")
print(title)
content = re.findall('<dl class="stabcon stabcon1" id="mv-Basic">(.*?)</dl>', html)[0]
content = content.split('<dt>')[1:]
for each in content:
each = each.split('</dt>')
category = each[0]
lists = re.findall('<a [^>].*?>(.*?)</a>', each[1])
print(category)
print(lists)
最后输出这样:
电影名:
羞羞的铁拳
导演
['张吃鱼 Chiyu Zhang', '宋阳 Yang Song']
演员
['艾伦 Allen Ai', '马丽 Li Ma', '沈腾 Teng Shen', '田雨 Yu Tian', '薛皓文 Haowen Xue', '常远 Yuan Chang', '黄才伦 Cailun Huang', '王成思 ', '高海宝 Gao Haibao', '高旭东 Gao Xundong', '李海银 Haiyin Li', '杨阳 Yang Yang', '龚锐 Gong Rui', '贾金金 ', '宋阳 Yang Song', '尹正 Zheng Yin', '王智 Zhi Wang']
制作公司
['北京开心麻花影业有限公司 Beijing happy twist film Co.,Lts', '天津猫眼文化传媒有限公司 Tianjin Maoyan Media Co.,Ltd ', '新丽传媒股份有限公司 New Classic Media Corporation', '万达影视传媒有限公司 Wanda Media Co., Ltd', '横店影视制作有限公司 HG Entertainment Co.,Ltd', '大地时代文化传播(北京)有限公司 Dadi Century Films(Beijing)Co.,Ltd', '北京金逸嘉逸电影发行有限公司 Beijing Jinyi Jiayi Film Distribution Co.,Ltd', '捷成世纪文化产业集团有限公司 Jiecheng Shiji Cultural Industry Group Co.,Ltd', '上海淘票票影视文化有限公司 Shanghai Tao Piao Piao Entertainment Co.,Ltd ', '北京市文化投资发展集团有限责任公司 Beijing Culture Investment Group', '北京天浩盛世影业有限公司 Beijing Tianhao Shengshi Pictures Co.,Ltd', '霍尔果斯开心麻花文化科技有限公司 ', '锦元素国际传媒北京有限公司 ']
发行公司
['天津猫眼文化传媒有限公司 Tianjin Maoyan Media Co.,Ltd ', '华夏电影发行有限责任公司 Huaxia Film Distribution Co.,Ltd', '四海电影发行联盟 Sihai Distribution Association', '上海电影股份有限公司影视发行分公司 Eastern Mordor']