So I'm trying to scrape data from this URL ( https://brainbooks.pk/past-papers.php ). I'm using Selenium Python Select for Drop Down Menus. I want to select by ID cause by names causing problems in loop. Initially 2nd drop down (Select Subject) id = 'subjepct'
but as soon as any option from 1st drop down (Select Class) is selected id changes to id='subject'
.
Is there any way there I can edit and assign new value to this id value before selecting drop down, Probably after the web page loads?
HTML ELEMENT NOW: <select id="subjepct" name="subject" onchange="getType(this);">
REQUIRED RESULT: <select id="subject" name="subject" onchange="getType(this);">
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://brainbooks.pk/past-papers.php')
Class_Element_drop_Down = driver.find_element_by_id("class")
Class_drop_Down = Select(Class_Element_drop_Down)
Class_Options = Class_drop_Down.options
for opt1 in Class_Options:
opt1.click()
Subject_Element_drop_Down = driver.find_element_by_id("subject")
Subject_drop_Down = Select(Class_Element_drop_Down)
Subject_Options = Subject_drop_Down.options
time.sleep(5)
for opt2 in Subject_Options:
opt2.click()
Board_Element_drop_Down = driver.find_element_by_id("type")
Board_drop_Down = Select(Class_Element_drop_Down)
Board_Options = Board_drop_Down.options
for opt3 in Board_Options:
opt3.click()
Year_Element_drop_Down = driver.find_element_by_id("size")
Year_drop_Down = Select(Class_Element_drop_Down)
Year_Options = Year_drop_Down.options
for opt4 in Year_Options:
opt4.click()
So I'm trying to scrape data from this URL ( https://brainbooks.pk/past-papers.php ). I'm using Selenium Python Select for Drop Down Menus. I want to select by ID cause by names causing problems in loop. Initially 2nd drop down (Select Subject) id = 'subjepct'
but as soon as any option from 1st drop down (Select Class) is selected id changes to id='subject'
.
Is there any way there I can edit and assign new value to this id value before selecting drop down, Probably after the web page loads?
HTML ELEMENT NOW: <select id="subjepct" name="subject" onchange="getType(this);">
REQUIRED RESULT: <select id="subject" name="subject" onchange="getType(this);">
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://brainbooks.pk/past-papers.php')
Class_Element_drop_Down = driver.find_element_by_id("class")
Class_drop_Down = Select(Class_Element_drop_Down)
Class_Options = Class_drop_Down.options
for opt1 in Class_Options:
opt1.click()
Subject_Element_drop_Down = driver.find_element_by_id("subject")
Subject_drop_Down = Select(Class_Element_drop_Down)
Subject_Options = Subject_drop_Down.options
time.sleep(5)
for opt2 in Subject_Options:
opt2.click()
Board_Element_drop_Down = driver.find_element_by_id("type")
Board_drop_Down = Select(Class_Element_drop_Down)
Board_Options = Board_drop_Down.options
for opt3 in Board_Options:
opt3.click()
Year_Element_drop_Down = driver.find_element_by_id("size")
Year_drop_Down = Select(Class_Element_drop_Down)
Year_Options = Year_drop_Down.options
for opt4 in Year_Options:
opt4.click()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.