【发布时间】:2020-05-14 00:07:35
【问题描述】:
我正在尝试使用 python 从网页中获取产品名称。但它只返回一个空标签。我还尝试了requests 库和lxml 解析BeautifulSoup。请帮我解决这个问题,在此先感谢:-)
网站中的 HTML:
<div class="product-name">SWAN</div>
<div class="product-price">
<span class="final-price">₹10650</span>
</div>
<div class="specification">
<div>Specifications</div>
<table>
<tr>
<td>....</td>
</tr>
<tr>
<td>....</td>
</tr>
</table>
</div>
python 代码:
url = "http://opor.in/ProductDetail/Index?ProductId=212"
page = urlopen(url).read()
html = bs(page, 'html.parser')
model_name = html.find('div', attrs={'class':'product-name'})
spec = html.find('div', attrs={'class':'specification'})
print(model_name)
print(spec)
输出:
<div class="product-name"></div>
<div class="specification">
<div>Specifications</div>
<table></table>
</div>
【问题讨论】:
标签: javascript python html web-scraping beautifulsoup