[ 我怎么能从这个烂摊子中得到价格。]
<li class="price-current">
<span class="price-current-label">
</span>₹ 36,659 <a class="price-current-num" href="https://www.newegg.com/global/in-en/gigabyte-geforce-rtx-2070-super-gv-n207swf3oc-8gd/p/N82E16814932213?Item=N82E16814932213&buyingoptions=New">(3 Offers)</a>
<span class="price-current-range">
<abbr title="to">–</abbr>
</span>
</li>
答案 0 :(得分:1)
您可以将.find_next_sibling()
与text=True
参数一起使用来确定价格:
data = '''<li class="price-current">
<span class="price-current-label">
</span>₹ 36,659 <a class="price-current-num" href="https://www.newegg.com/global/in-en/gigabyte-geforce-rtx-2070-super-gv-n207swf3oc-8gd/p/N82E16814932213?Item=N82E16814932213&buyingoptions=New">(3 Offers)</a>
<span class="price-current-range">
<abbr title="to">–</abbr>
</span>
</li>'''
from bs4 import BeautifulSoup
soup = BeautifulSoup(data, 'html.parser')
print(soup.select_one('.price-current-label').find_next_sibling(text=True))
打印:
₹ 36,659