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未加载整页源代码_Python_Selenium_Web - Fatal编程技术网

Python Selenium未加载整页源代码

Python Selenium未加载整页源代码,python,selenium,web,Python,Selenium,Web,Selenium网页中的源代码似乎不完整 driver = webdriver.Chrome() driver.get('https://www.youtube2mp3.cc/') vid_name = driver.find_element_by_id('input') vid_name.send_keys('https://www.youtube.com/watch?v=NVbH1BVXywY') driver.find_element_by_id('button').click()

Selenium网页中的源代码似乎不完整

driver = webdriver.Chrome()
driver.get('https://www.youtube2mp3.cc/')

vid_name = driver.find_element_by_id('input')
vid_name.send_keys('https://www.youtube.com/watch?v=NVbH1BVXywY') 
driver.find_element_by_id('button').click()


element = WebDriverWait(driver, 5).until(
        EC.presence_of_element_located((By.ID, 'download'))
)


url = driver.page_source
url = str(url)
soup = BeautifulSoup(url,"html.parser")
print(soup)
当我访问soup时,href是空的

<a href="" id="download" rel="nofollow">Download</a>


当我使用延时时,它似乎工作正常,但我想知道如何使用WebDriverWait来确保id为download的href加载。

WebDriverWait
等待,直到下载按钮有
href

element = WebDriverWait(driver, 5).until(
        EC.presence_of_element_located((By.XPATH, './/a[@id="download" and @href!=""]'))
)
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.Chrome()
driver.get("https://www.youtube2mp3.cc/")
try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "download"))
    )