Skip to content Skip to sidebar Skip to footer

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 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"))  

Solution 3:

just select them based on the option tag.

country= driver.find_elements_by_css_selector('option')

New for loop:

    for i in range(items):
        s.write(cur[i].text + ',' + country[i].get_attribute["value"] + '\n')

Post a Comment for "How To Scrape Values In Selenium Using Python?"