【发布时间】:2017-12-13 12:08:47
【问题描述】:
我正在使用 css 选择器解析 html 页面
import requests
import webbrowser
from bs4 import BeautifulSoup
page = requests.get('http://www.marketwatch.com', headers={'User-Agent': 'Mozilla/5.0'})
soup = BeautifulSoup(page.content, 'html.parser')
在使用 select 方法时,我无法选择带有类的列表标记。但是,我在使用 find_all 方法时没有问题
soup.find_all('ul', class_= "latestNews j-scrollElement")
这会返回我想要的输出,但由于某种原因,我不能使用 CSS 选择器。我想知道我做错了什么。
这是我的尝试:
soup.select("ul .latestNews j-scrollElement")
返回一个空列表。
我无法弄清楚我在使用 select 方法时做错了什么。
谢谢。
【问题讨论】:
标签: python beautifulsoup css-selectors