我正试图从https://www.sunnxt.com/movie/inside/网站获取电影名称。当我去检查元素时,它会向我显示带有电影名称的元素,但是当我执行css选择器或xpath表达式时,它没有给出电影名称。
当我点击查看源时,我看到代码有所不同。并且所有电影数据都放在
<script></script>标签之间。
请帮助我获取所有电影名称。
答案 0 :(得分:2)
要检索电影名称,您必须将WebDriverWait与expected_conditions联系为visibility_of_all_elements_located,如下所示:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver=webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get("https://www.sunnxt.com/movie/inside/")
movieList = WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, "//h2[@class='title']//following::div[@class='home_movie_list_wrap']//a//h2")))
for item in movieList:
print(item.text)
driver.quit()
控制台输出:
Gulaebaghavali
KALAKALAPPU 2
Motta Shiva Ketta Shiva
Annadurai
Aramm
Kaththi Sandai
Meesaya Murukku
Spyder
Sathriyan
Bogan
Brindavanam
Vivegam
Bairavaa
Karuppan
Muthina Kathirika
Dharmadurai
Thozha
Pichaikkaran
Devi
Aranmanai 2
Jackson Durai
Hello Naan Pei Pesuren
Kathakali
Kodi