[英]"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"))
""" 回溯(最近一次调用最后一次):文件 "C:/Users/user/Desktop/python_project/entry_exampe4.py", line 32, in for ii in data: TypeError: 'WebElement' object is not iterable """当我在制作 python 爬虫程序时,我确实有这个错误代码如何修复代码?
您需要使用driver.find_elements_by_xpath
而不是driver.find_element_by_xpath
。
注意element
后面有一个s
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.