【发布时间】:2021-05-26 23:19:46
【问题描述】:
在美丽的汤中,我如何检索嵌套元素?
下面我正在尝试检索产品的名称,即: LAP 13A 2-Gang SP 开关插座 + 3.1A 2-Outlet Type A USB 充电器 白色
<h1 id="product_description" tabindex="0">
<span itemprop="name">
LAP 13A 2-Gang SP Switched Socket + 3.1A 2-Outlet Type A USB Charger White
</span>
<span class="sm" id="product_code_container">
(<span itemprop="productID">4087P</span>)
<meta itemprop="sku" content="4087P">
</span>
</h1>
我尝试了下面的代码,但没有返回任何产品名称,只是空白:
soup = bs(page.content, 'html.parser')
product_title = soup.find('h1',attrs={'id':'product_description'}).find('span', attrs={'itemprop':'name'})
products.append(product_title.text)
【问题讨论】:
-
请问网址是什么?它可能是动态添加的。
标签: python beautifulsoup