|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Firefox()
driver.implicitly_wait(20)
driver.get("http://www.santostang.com/2018/07/04/hello-world/")
time.sleep(5)
for i in range(0,3):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR,"iframe[title='라이브리 - 댓글영역']"))
load_more = driver.find_element(By.XPATH,"/html/body/div/div[1]/div[8]/div[8]/div[2]")
load_more.click()
driver.switch_to.default_content()
time.sleep(5)
driver.switch_to.frame(driver.find_element(By.CSS_SELECTOR,"iframe[title='라이브리 - 댓글영역']"))
comments = driver.find_element(By.CSS_SELECTOR,'div.reply-content')
for eachcomment in comments:
content = eachcomment.find_element(By.TAG_NAME,'p')
print(content.text)
if i == 0:
temp_xpath = "/html/body/div/div[1]/div[8]/div[11]/button[" + str(i + 2) + "]"
if i == 1:
temp_xpath = "/html/body/div/div[1]/div[8]/div[11]/button[" + str(i + 2) + "]"
if i == 2:
print("The above are the comments in the {}th page.".format(i + 1))
print("Finish!")
if i < 2:
print("Thevalue of i is:",i)
print("The above are the comments in the {}th page.".format(i+1))
print("The xpath of the next page:",temp_xpath)
next_page = driver.find_element(By.XPATH,temp_xpath)
next_page.click()
driver.switch_to.default_content()
time.sleep(5)
报错:Traceback (most recent call last):
File "d:\Desktop\0328.py", line 17, in <module>
for eachcomment in comments:
TypeError: 'WebElement' object is not iterable |
|