【发布时间】:2020-10-27 21:00:11
【问题描述】:
我正在尝试解析 txt 文件的一组 url,但 Beautiful Soup 只返回最后一个 url 的内容。这是一组来自 LetterBoxD 网站的电影评论网址。例如,如果文件有 10 个 url,前 9 个我得到“无”。只有第 10 个正确返回。有人可以帮我吗?
from bs4 import BeautifulSoup
import requests
with open('list_of_urls.txt', 'r') as f:
x = f.readlines()
for url in x:
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
text = soup.find(class_='review body-text -prose -hero -loose')
print(text)
【问题讨论】:
-
可能你指定的类只存在于最后一个url的页面源中?
-
介意分享这 10 个网址的样本吗?
标签: web-scraping beautifulsoup python-requests