【发布时间】:2018-09-11 04:00:18
【问题描述】:
网站上有这个<a>元素
<a role="listitem" aria-level="1" href="https://www.rest.co.il" target="_blank" class="icon rest" title="this is main title" iconwidth="35px" aria-label="website connection" style="width: 30px; overflow: hidden;"></a>
所以我用这段代码来捕捉元素
(注意 find_all 参数 a.icon.rest)
import requests
from bs4 import BeautifulSoup
url = 'http://www.zap.co.il/models.aspx?sog=e-cellphone&pageinfo=1'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "html.parser")
for link in soup.find_all("a.icon.rest"):
x = link.get('href')
print(x)
不幸的是,它什么也没返回
尽管美丽的汤文档清楚地表明:
如果你想搜索匹配两个或更多 CSS 类的标签,你 应该使用 CSS 选择器:
css_soup.select("p.strikeout.body")
returns: <p class="body strikeout"></p>
那么为什么这不起作用? 顺便说一句,我用的是pycharm
【问题讨论】:
标签: python beautifulsoup css-selectors