猫眼top100电影信息爬虫

代码如下
import requests
from requests.exceptions import RequestException
import re
def get_one_page(url):
try:
headers={‘User-Agent’:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36’}
response=requests.get(url,headers=headers)
if response.status_code==200:
return response.text
return None
except RequestException:
return None

def parse_one_page(html):
pattern=re.compile(’

. ?board-index-1">(\d+).?data-src="(. ?)".?/>. ?name">?>(. ?)’+
'.
?star">(. ?)

.?releasetime">(. ?).?integer">(. ?).?fraction">(. ?).?’,re.S)
items=re.findall(pattern,html)
print(items)

def main():
url=‘http://maoyan.com/board/4?’
html=get_one_page(url)
parse_one_page(html)

if name==‘main’:
main()
显示结果如下
C:\Users\Administrator\python37\python.exe C:/Users/Administrator/PycharmProjects/Maoyantop100/spder.py
[(‘1’, ‘https://p1.meituan.net/movie/20803f59291c47e1e116c11963ce019e68711.jpg@160w_220h_1e_1c’, ‘霸王别姬’, '\n 主演:张国荣,张丰毅,巩俐\n ', ‘上映时间:1993-01-01’, ‘9.’, ‘5’)]

Process finished with exit code 0
一个页面是10个电影,为什么只能爬到第一信息,后面都没有呢,求指教

你可能感兴趣的:(猫眼top100电影信息爬虫)