'"TypeError: 'WebElement' object is not iterable" error code python crawling
from bs4 import BeautifulSoup
from selenium import webdriver
url = 'http://www.powerballgame.co.kr/?view=dayLog'
driver = webdriver.PhantomJS('C:\\Users\\user\\Downloads\\phantomjs-2.1.1-
windows\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
driver.get(url)
delay_time = 2
driver.implicitly_wait(delay_time)
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
real**strong text**time_round = soup.select('table.powerballBox >
tbody.content > tr > td > span.numberText')
table = soup.find('table',{'class': 'numberText'})
for round in realtime_round:
print(round.text)
#realtime_result = soup.select('table.powerballBox > tbody.content > tr > td
> div.sp-ball_bg')
#for result in realtime_result:
driver.get(url)
data=driver.find_element_by_xpath("//*
[@id='powerballLogBox']/tbody[2]/tr[4]/td[3]/div")
for ii in data:
print(ii.get_attritbute("href"))
""" Traceback (most recent call last): File "C:/Users/user/Desktop/python_project/entry_exampe4.py", line 32, in for ii in data: TypeError: 'WebElement' object is not iterable """ When I was making python crawling program I did have this error code How I can fix code?
Solution 1:[1]
You need to use driver.find_elements_by_xpath instead of driver.find_element_by_xpath.
Note there is an s behind element
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Daniel Qiao |
