【发布时间】:2018-01-08 17:59:12
【问题描述】:
This 是我想使用 BeautifulSoup 从以下站点 (https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Examination) 解析的源代码的图像。我希望提取 属性中的属性:htm 链接。
我的 python 代码如下所示:
import urllib.request
try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
url = "https://wwwn.cdc.gov/nchs/nhanes/search/datapage.aspx?Component=Examination"
with urllib.request.urlopen(url) as page:
html_source = page.read()
soup = BeautifulSoup(html_source, 'html5lib')
link = soup.findAll("span", {"class":"print-only"})
打印“链接”会返回一个空列表。我知道 html 代码中有 span 元素,因为 soup.findAll("span") 返回 html 代码(尽管在这些 span 元素的内容中我没有看到一个名为 'print-only' 的类)。
我注意到 span 属性在 Firefox 开发者窗口中显示为灰色。快速谷歌搜索显示这意味着该属性是隐藏的。是不是说明我用的方法无法获取?
【问题讨论】:
标签: python html beautifulsoup