Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用selenium检查时,大多数HTML元素为空_Python_Selenium_Selenium Webdriver_Web Scraping - Fatal编程技术网

Python 使用selenium检查时,大多数HTML元素为空

Python 使用selenium检查时,大多数HTML元素为空,python,selenium,selenium-webdriver,web-scraping,Python,Selenium,Selenium Webdriver,Web Scraping,我正在学习用硒来刮网。Inspect显示我正在搜索的元素具有类名“movie link”。这是我的密码: def get_movies(driver, name, scroll_num): elem = driver.find_element_by_class_name("form-control") elem.clear() elem.send_keys(name) elem.send_keys(Keys.RETURN) scroll_down(dri

我正在学习用硒来刮网。Inspect显示我正在搜索的元素具有类名“movie link”。这是我的密码:

def get_movies(driver, name, scroll_num):
    elem = driver.find_element_by_class_name("form-control")
    elem.clear()
    elem.send_keys(name)
    elem.send_keys(Keys.RETURN)

    scroll_down(driver, scroll_num)

    return map(lambda x: x.get_attribute('href'), driver.find_elements_by_class_name('movie-link'))
driver.find\u elements\u by\u class\u name('movie-link')
找不到任何内容,因此我(使用selenium)检查了包含“movie link”的元素,其内部HTML是“placeholder”

这是某种保护还是我忘了什么

编辑: 我正在尝试解析显式等待:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

movies = WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".movie-link"))
显式等待:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

movies = WebDriverWait(driver,10).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".movie-link"))

添加等待
所有元素的存在\u位置
。共享url或htmlwelcome到stackoverflow。这是一个合理的好问题。通过向要解析的页面添加链接,您可以使其变得更好。很可能该页面是使用JS框架构建的,因此在加载主HTML时,所有内容可能都不可用。@谢谢。添加等待
presence\u所有元素的位置
。共享url或htmlwelcome到stackoverflow。这是一个合理的好问题。通过向要解析的页面添加链接,您可以使其变得更好。页面很可能是使用JS框架构建的,因此在加载主HTML时,所有内容可能都不可用。谢谢。