【发布时间】:2022-01-03 12:05:07
【问题描述】:
我想使用 python 的 BeautifulSoup 从这部分 html 代码中提取有关年份、公里数和颜色的信息。有人可以帮帮我吗?
<h3 class="topNavTitle" id="techParams">Tech parms</h3>
<div class="techParamsRow general">
<div class="col col12M pr20">
<table class="transparentTable">
<tr>
<th>Year</th><td>2014</td>
</tr>
<tr>
<th>Kms</th><td>103 472 km</td>
</tr>
<tr>
<th>Color</th><td>white</td>
</tr>
</table>
</div>
我试过了:
res = requests.get(website)
soup = BeautifulSoup(res.content, "html.parser")
results = soup.find('div', {'class': 'techParamsRow general'})
print(results)
但它什么也没找到。 谢谢!
【问题讨论】:
-
未找到任何东西是什么意思 - 您的选择不是特定于获取表格,但它会找到您的 div。总是先看看你的汤——这就是真相。
print(soup)-> 你在汤里找到 html 了吗?使用信息更新您的问题,并提供您的预期结果。谢谢
标签: python html web-scraping beautifulsoup