Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将div中的2个内部文本作为一个值刮除_Python_Python 2.7 - Fatal编程技术网

Python 将div中的2个内部文本作为一个值刮除

Python 将div中的2个内部文本作为一个值刮除,python,python-2.7,Python,Python 2.7,我有下面的html <div class="price-block__highlight"><span class="promo-price" data- test="price">102, <sup class="promo-price__fraction" data-test="price-fraction">99</sup> </span> </div> 然而,这导致: 102. 99 在csv中写入时,

我有下面的html

<div class="price-block__highlight"><span class="promo-price" data- 
test="price">102,
<sup class="promo-price__fraction" data-test="price-fraction">99</sup>
</span>

</div>
然而,这导致:

 102.
  99

在csv中写入时,会创建多行。如何在一个值中获取两个数字?

我认为您使用的是
bs4

from bs4 import BeautifulSoup

html_doc = """
<div class="price-block__highlight"><span class="promo-price" data-
test="price">102,
<sup class="promo-price__fraction" data-test="price-fraction">99</sup>
</span>

</div>
"""

soup = BeautifulSoup(html_doc, 'html.parser')

price_div = soup.find("div", {"class": 'price-block__highlight'})

texts = [x.strip() for x in price_div.text.split(',')]

print('.'.join(texts))
从bs4导入美化组
html_doc=“”
102,
99
"""
soup=BeautifulSoup(html_doc,'html.parser')
price\u div=soup.find(“div”,“class”:“price-block\u highlight”})
text=[x.strip()表示price_div.text.split(',')中的x
打印('..'.join(文本))
输出

102.99

from bs4 import BeautifulSoup

html_doc = """
<div class="price-block__highlight"><span class="promo-price" data-
test="price">102,
<sup class="promo-price__fraction" data-test="price-fraction">99</sup>
</span>

</div>
"""

soup = BeautifulSoup(html_doc, 'html.parser')

price_div = soup.find("div", {"class": 'price-block__highlight'})

texts = [x.strip() for x in price_div.text.split(',')]

print('.'.join(texts))