[英]beautiful soup printing nothing
I'm trying to have beautiful soup pull info from a website and have it print just in the console.我正在尝试从网站获取漂亮的拉汤信息,并将其打印在控制台中。 When it does it, its printing
[]
and i have no clue how to fix it.当它这样做时,它的打印
[]
我不知道如何修复它。
soup = BeautifulSoup(page_source, "html.parser")
mlsspan = soup.find_all("td.d1m8")
print(mlsspan)
html being pulled html 被拉
<td class="d1m8">
<span class="d1m1">
<a href="javascript:__doPostBack('m_DisplayCore','Redisplay|188,,0')">A11033427</a>
</span>
</td>
I can't give the website because its password protected.我不能给网站,因为它的密码保护。
I'm trying to get the A11033427
from the <a>
tag.我正在尝试从
<a>
标记中获取A11033427
。
i've also tried我也试过
mlsspan = soup.find_all("td.d1m1")
Instead of .find_all
use .select_one
/ .select
.而不是
.find_all
使用.select_one
/ .select
。 .find_all
doesn't accept CSS selectors: .find_all
不接受 CSS 选择器:
from bs4 import BeautifulSoup
html_doc = """
<td class="d1m8">
<span class="d1m1">
<a href="javascript:__doPostBack('m_DisplayCore','Redisplay|188,,0')">A11033427</a>
</span>
</td>
"""
soup = BeautifulSoup(html_doc, "html.parser")
print(soup.select_one("td.d1m8 a").text)
Prints:印刷:
A11033427
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.