如何使用Python报废Selenium中的值? [英] How To Scrap Values in Selenium Using Python?
问题描述
我正在尝试使用CSS选择器来废除选项标签中的值,但我不能:
I'm Trying To Scrap Values in option tag with css selector but i can't:
我想在选项标记中例如在<option value='i want to scrap this'>text</option>
I Want to scrap values attribute in option tag for example <option value='i want to scrap this'>text</option>
这是另一个屏幕截图,因此您可以更好地理解:
Here is another Screenshot so you can understand better:
在选项标签中,我要取消输入值而不是文本
in the option tag i want to scrap values not text
您可以看到这里是选项值的屏幕截图:
You Can See Here is the option values screenshot:
我也想在此处取消值
这是我的代码:
cur = driver.find_elements_by_css_selector('#id_currency')
country = driver.find_elements_by_css_selector('search-form-place-country')
items = len(cur)
with open('cur.csv','w') as s:
for i in range(items):
s.write(cur[i].text + ',' + country[i].text + '\n')
任何帮助都会得到赞赏
谢谢!
推荐答案
使用
To extract the values with in the <option>
tag with using css-selectors you can use the following Locator Strategy:
from selenium import webdriver
from selenium.webdriver.support.ui import Select
select_places = Select(driver.find_element_by_css_selector("select.search-form-place.select.form-control"))
for option in select_places.options:
print(option.get_attribute("value"))
这篇关于如何使用Python报废Selenium中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!