我正在尝试从以下链接中抓取评论:http://www.phimmoi.net/phim/the-gioi-phep-mau-i1-6113/xem-phim.html。这是我使用的代码:
find_comment = browser.find_elements_by_css_selector("div[class='_3-8y _5nz1 clearfix']")
for i in find_comment:
element_comment = i.find_element_by_css_selector("span[class='_5mdd']")
print(element_comment.text)
但是什么也没发生:没有错误,没有异常,什么也没打印。
网站锁是否已爬网?如果是,请帮助我知道。
答案 0 :(得分:1)
您在发布的网站上的评论位于iframe
中,因此您需要切换到iframe
才能找到评论。
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# first switch to the iframe
WebDriverWait(browser, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@title, 'fb:comments')]")))
# then get comments
comments_list = browser.find_elements_by_xpath("//span[@class='_5mdd']/span")
# iterate the comments
for comment in comments_list:
# print the comment text element -- the span which contains the commment text
print(comment.text)
答案 1 :(得分:0)
find_comment = browser.find_elements_by_css_selector("._3-8y _5nz1 clearfix")
for i in read_more:
element_comment = i.find_element_by_css_selector("._5mdd")
print(element_comment.text)