macOS Catalina 10.15.3 Python 3.6.5 selenium 3.141.0
Scraping Google search results with python selenium Extract the extracted elements to the list with a for loop
'WebElement' object is not iterable Translation:'WebElement' object is not repeatable
Here, it was an error that occurred when performing a for loop, so the point is ‘Xxx’ specified as the reference source in for i in xxx cannot retrieve the repeating element. It is that.
At this time, the pre-processing using seleniumu is omitted.
title_list = []
link_list = []
i = 1
i_max = 2
while i <= i_max:
w = driver.find_element_by_class_name(“x”)
for elem in x:
title_list.append(elem.find_element_by_class_name(‘y’).text)
link_list.append(elem.find_element_by_tag_name(‘a’).get_attribute('href'))
Error occurred in the above code
TypeError: 'WebElement' object is not iterable
#7th line here
w = driver.find_element_by_class_name(“x”)
.find_element extracts only a single element, so it's not repeatable.
# .find_elements… please
w = driver.find_elements_by_class_name(“x”)
You have to be careful about whether you need a single element extraction or multiple elements. I learned a lot.
"I tried to extract the Google search title and URL list with Python" https://watlab-blog.com/2019/08/15/python-google-searchlist/