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)
当我访问汤时,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!=""]'))
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句