美丽的汤:无法从中获取文字(价格)

时间:2019-12-09 17:19:53

标签: python html python-3.x beautifulsoup

[ 我怎么能从这个烂摊子中得到价格。]

<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&amp;buyingoptions=New">(3 Offers)</a>
               <span class="price-current-range">
               <abbr title="to">–</abbr>
               </span>
 </li>

Image

1 个答案:

答案 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&amp;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