我有以下代码输出从<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
上述代码块在输出下列情况时存在问题,考虑^ {< CD3>},^ {< CD4>}。
我尝试了以下方法,但不幸的是没有成功
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>
1821中的空格似乎是不间断空格(导致输出中出现\u202f),请尝试对此进行替换。顺便说一句,我不知道这个字符在键盘上的什么位置,但是复制/粘贴就足够了
相关问题 更多 >
编程相关推荐