Python Forum
Find all values in drop down menu with bs4 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Find all values in drop down menu with bs4 (/thread-34522.html)



Find all values in drop down menu with bs4 - DonaldBug13 - Aug-06-2021

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)



RE: Find all values in drop down menu with bs4 - Axel_Erfurt - Aug-06-2021

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