Python Forum

Full Version: Find all values in drop down menu with bs4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi. I want to find all values from the select option tag but I don't know how. I need the value, not the text.
Yeah the URL for my bs4 experiment is a german website for stocks.
If you want to test the code by yourself:
("Monat" = month, "letzten 30 Tage" = last 30 days)
Thats the option menu I mean.

from bs4 import BeautifulSoup
import requests

main_site = requests.get("https://www.ariva.de/ether-kurs/historische_kurse")
soup = BeautifulSoup(main_site.content, 'html.parser')
website = soup.find(attrs={'id':'WEBSEITE'})
select = website.find(attrs={'name':'month'})
option = select.find_all('option')
print(option)
maybe this

from bs4 import BeautifulSoup
import requests
 
main_site = requests.get("https://www.ariva.de/ether-kurs/historische_kurse")
soup = BeautifulSoup(main_site.content, 'html.parser')
website = soup.find(attrs={'id':'WEBSEITE'})
select = website.find(attrs={'name':'month'})
for option in select.find_all('option'):
    print(option["value"])