一个豆瓣网页简单网页内容的提取
我写到能打印出下文中包含要提取内容的html,但后面就不知道怎么提取了,试了好久都没成功,就是提取上映的电影的名称,评分,参演人员的信息,大家能帮我试试看吗import requests
import re
import xlwt
from lxml import html
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")
nfo = page.find_all("div",class_= "mod-bd")
for i in info:
title = i.find('li')
print(title)
print("结束") 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").find_all("li", class_="list-item")
for i in info:
actors = re.findall(r'data-actors="(.*?)"', str(i))
title = re.findall(r'data-title="(.*?)"', str(i))
score = re.findall(r'data-score="(.*?)"', str(i))
score = score if score != ["0"] else "暂无评分"
print(actors, title, score)
print("结束")
页:
[1]