Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/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不会打印整个页面_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Python selenium不会打印整个页面

Python selenium不会打印整个页面,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我试图从一个网页上获取html代码,但我只得到显示的页面的1/4 从bs4导入美化组 从selenium导入webdriver driver=webdriver.Chrome() 驱动程序。获取(“https://www.hltv.org/matches") 打印(驱动程序页\源) 感觉好像我什么都试过了,但结果还是一样。它不是从顶部开始的。它从很远的地方开始,几乎到了尽头 有人有线索吗?可能是因为在打印时,get尚未完成加载页面 要解决此问题,可以尝试在打印之前等待加载已知元素 要等待加载元

我试图从一个网页上获取html代码,但我只得到显示的页面的1/4

从bs4导入美化组
从selenium导入webdriver
driver=webdriver.Chrome()
驱动程序。获取(“https://www.hltv.org/matches")
打印(驱动程序页\源)
感觉好像我什么都试过了,但结果还是一样。它不是从顶部开始的。它从很远的地方开始,几乎到了尽头


有人有线索吗?

可能是因为在打印时,get尚未完成加载页面

要解决此问题,可以尝试在打印之前等待加载已知元素

要等待加载元素(“下例中的backToLoginDialog”),请将代码调整为如下所示:

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

# set up driver and page load timeout
driver = webdriver.Chrome()
timeout = 5

# create your "wait" function
def wait_for_load(element_id):
    element_present = EC.presence_of_element_located((By.ID, element_id))
    WebDriverWait(driver, timeout).until(element_present)

driver.get('https://www.hltv.org/matches')
wait_for_load('backToLoginDialog')
print(driver.page_source)

请尝试下面的代码。这对我有用

from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.hltv.org/matches")
file = open("asd.html", "a", encoding='utf8')
file.write(driver.page_source)
file.close()

这回答了你的问题吗?我不想截屏。我正在寻找的html代码。没有得到它的工作。我不是专家,所以这段代码可能有效,但有一些错误。无论如何,谢谢。我在以前的版本中做了一次编辑(忘记包括WebDriverWait)。这在我的系统上运行得很好,直接从这篇文章中复制和粘贴-我还在页面本身上找到了“backToLoginDialog”来测试负载。不过,看起来你在任何情况下都找到了解决方案:)