【发布时间】:2020-11-03 07:19:48
【问题描述】:
很简单的代码
import requests
from bs4 import BeautifulSoup
link = 'https://www.birdsnest.com.au/brands/boho-bird/73067-amore-wrap-dress'
page = requests.get(link)
soup = BeautifulSoup(page.content, 'html.parser')
page_new = soup.find('div', class_='model-info clearfix')
results = page_new.find_all('p')
for result in results:
print(result.text)
输出
usually wears a size .
She is wearing a size in this style.
Her height is .
Show ’s body measurements
问题在于模型的名称在<strong> 标签内,span 在<strong> 标签内。
像这样。
<div class="model-info-header">
<p>
<strong><span class="model-info__name">Marnee</span></strong> usually wears a size <strong><span class="model-info__standard-size">8</span></strong>.
She is wearing a size <strong><span class="model-info__wears-size">10</span></strong> in this style.
</p>
<p class="model-info-header__height">Her height is <strong><span class="model-info__height">178 cm</span></strong>.</p>
<p>
<span class="js-model-info-more model-info__link model-info-header__more">Show <span class="model-info__name">Marnee</span>’s body measurements</span>
</p>
</div>
如何获取<p>标签内的BOLD元素。
【问题讨论】:
标签: python html web-scraping beautifulsoup