我有以下代码输出从<div>
标签中提取的数据。
s = BeautifulSoup(driver.page_source, "lxml")
best_price_tags = s.findAll('div', "flt-subhead1 gws-flights-results__price gws-flights-results__cheapest-price")
best_prices = []
for tag in best_price_tags:
best_prices.append(tag.text.replace('€', '').strip())
变量best_price_tags
的第一个元素包含以下内容:
<div class="flt-subhead1 gws-flights-results__price gws-flights-results__cheapest-price"> 1 820 € </div>
我希望上面的代码只输出值 1821。
上面的代码块有一个问题,它输出以下内容,考虑best_price_tags[0]
、'1u202f821'
的情况。
我尝试了以下方法,但不幸的是对我不起作用。
for tag in best_price_tags:
best_prices.append(int(tag.text.replace('€', '').strip()))
寻找不使用NLP模块的自动化解决方案。
注意:我已经编辑了<div>
标签的确切值。它曾经<div class='...'>1 820 €</div>
,现在它<div class='...'> 1 820 € </div>
.
1 821 中的空格似乎是一个不间断的空间(导致输出中的 \u202f(,请尝试对此进行替换。顺便说一句,我不知道这个字符在键盘上的位置,但复制/粘贴应该足够了