How To Scrape Values In Selenium Using Python?
I'm Trying To Scrape Values in option tag with css selector but i can't: I Want to scrape values attribute in option tag for example
Solution 1:
Use Select
class, it is specifically for <select>
dropdowns
from selenium.webdriver.support.select import Select
dropDown = driver.find_element_by_id('search-form-place-country')select = Select(dropDown)
with open('cur.csv','w') as s:foroptioninselect.options:
s.write(option.get_attribute('value') + '\n')
Solution 2:
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"))
foroptionin select_places.options:
print(option.get_attribute("value"))
Post a Comment for "How To Scrape Values In Selenium Using Python?"