Python Selenium 未加载整页源代码

标签 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()


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!=""]'))
)

关于Python Selenium 未加载整页源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38335292/

相关文章:

python - 将 firefox 配置文件传递给远程 webdriver firefox 实例不起作用

python zeep,如何更容易地找到方法/属性所属的绑定(bind)?

python - 我找不到有关TypeError : object of type 'bool' has no len() error的任何解决方案

java - Selenium 在 td 中搜索文本并获取同一行的另一个 td

http - POST 和 PATCH 动词有什么区别,我什么时候应该使用前者而不是后者?

python - 扬声器发出简单的蜂鸣声

java - 无法在具有两个月 block 的日期选择器中选择日期 - http ://www.cleartrip.com/flights

python - 选择第一个下拉列表后,第二个下拉列表发生变化

javascript - 即使页面完全渲染后,浏览器仍显示一半进度条

mysql - 将Vb.net 2013和Web连接到mysql