簡體   English   中英

“TypeError:'WebElement'對象不可迭代”錯誤代碼python爬行

[英]"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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM