转换时忽略字符

2024-09-30 18:23:54 发布

您现在位置:Python中文网/ 问答频道 /正文

使用命令:

cena_postov=driver.find_elements_by_xpath("//*[starts-with(@id, 'td_')]/td[11]/a[1]/span/span")
for spisok_cen in cena_postov:
  print(spisok_cen.get_attribute('textContent'))

我得到一个文本列表。我想用

if int(spisok_cen.get_attribute('textContent'))<=10 and int(spisok_cen.get_attribute('textContent'))>=12000:
 print('anything')

但是符号'让我很困扰。 我得到一个错误invalid literal for int() with base 10: ": 6'000 如何让python忽略这个字符


Tags: 命令forgetdriverwithattributeinttd
1条回答
网友
1楼 · 发布于 2024-09-30 18:23:54

可以使用replace方法删除不必要的'

if int(spisok_cen.get_attribute('textContent').replace("'", ""))<=10 and int(spisok_cen.get_attribute('textContent').replace("'", ""))>=12000:
    print('anything')

您还可以用localehere找到解决方案

相关问题 更多 >