python - scrape the value from a dropdown -


i trying web scrape value , text dropdown element on webpage using combination of python selenium , beautiful soup.

i able text not able value through get_attribute command.

when print element located on webpage returns following content

print(price)

the print statement gets gives error:

none type object not callable  price=soup.find("select",{"id":"space-prices"}) print(price) print(price.text) print(price.get_attribute('value')) 

the output print(price)

<select class="pricing-bar-select" id="space-prices" name="space-prices"><option selected="selected" value="£360">per day</option> <option value="£1,260">per week</option> <option value="£5,460">per month</option> <option value="£16,380">per quarter</option> <option value="£65,520">per year</option></select> 

the url of webpage

https://www.appearhere.co.uk/spaces/north-kensington-upcycling-store-and-cafe

try this:

from selenium import webdriver bs4 import beautifulsoup   driver = webdriver.chrome() url= "https://www.appearhere.co.uk/spaces/north-kensington-upcycling-store-and-cafe" driver.maximize_window() driver.get(url)  content = driver.page_source.encode('utf-8').strip() soup = beautifulsoup(content,"html.parser") price=soup.find("select",{"id":"space-prices"}) options = price.find_all("option") options1=[y.text y in options] values = [o.get("value") o in options] x in range(5):     print options1[x], values[x].encode('utf8') driver.quit() 

it print

per day £360 per week £1,260 per month £5,460 per quarter £16,380 per year £65,520 

hope want


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -