擅长:python、mysql、java
<p>或者,为了使事情更加通用和简单,您可以使用标签和制造商网站链接拆分字段处理:</p>
<pre><code>soup = BeautifulSoup(car, 'lxml')
car_info = soup.select_one('.info')
data = {
label.get_text(strip=True): label.find_next_sibling().get_text(strip=True)
for label in car_info.select('.infoEntity label')
}
data['manufacturer website'] = car_info.select_one('.infoEntity a').get_text(strip=True)
print(data)
</code></pre>
<p>印刷品:</p>
<pre><code>{'Headquarters': 'Dearbord, MI',
'Model': 'Mustang',
'manufacturer website': 'www.ford.com'}
</code></pre>