import requests
import re
from bs4 import BeautifulSoup
url = "https://movie.douban.com/cinema/nowplaying/haikou/"
head = { # 模拟浏览器头部信息,向豆瓣服务器发送消息
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Mobile Safari/537.36 Edg/100.0.1185.36"
}
resp = requests.get(url, headers=head)
content = resp.text
page = BeautifulSoup(content, "lxml")
info = page.find_all('div', id="nowplaying")[0].find_all("li", class_="list-item")
for i in info:
actors = re.findall(r'data-actors="(.*?)"', str(i))[0]
title = re.findall(r'data-title="(.*?)"', str(i))[0]
score = re.findall(r'data-score="(.*?)"', str(i))
score = score[0] if score != ["0"] else "暂无评分"
print(actors, title, score)
print("结束")
|