Know-how for specifying elements whose attributes change dynamically when scraping.
.html
<input id="sample_123456789">
I think there are many cases where you want to specify such an element every time, but you can specify it dynamically by using XPATH or CSS selector.
element = driver.find_elements_by_xpath('//*[starts-with(@id,"sample_")]')
If you write it like this, you can specify it dynamically.
element = driver.find_elements_by_css_selector("input[id^=sample_]")
element = driver.find_elements_by_css_selector("input[id*=sample_]")
It seems that you can specify it with the CSS selector as well.
Element-specific techniques [Selenium] How to get the id that changes dynamically python selenium: iterate through radio buttons that have dynamic ids and select
Recommended Posts