我在用硒刮擦。我想刮所有的视频网址,是存在于626产品在25页。但是在提取url时,它给了我图像文件源缩略图的href链接。
import selenium
import pandas as pd
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, ElementNotVisibleException,StaleElementReferenceException
#First we will connect to webdriver
driver=webdriver.Chrome(r'/Users/ankit/chromedriver')
#Open the webpage with webdriver
driver.get('https://www.getapp.com/hr-employee-management-software/human-resources/')
URL2 = [] # for product pages
URL = [] # for storing all the pages
for i in range(1, 27):
URL.append(f"https://www.getapp.com/hr-employee-management-software/human-resources/page-{i}/")
# visiting all the pages and scraping the products/Read More About... Links
for p in URL:
driver.get(p)
for i in driver.find_elements_by_xpath(
'//a[@data-testid="listing-item_text-link_read-more-about-product"]'
):
URL2.append(i.get_attribute("href"))
# extracting and storing the video url of the product
video_url=[]
for i in URL2:
driver.get(i)
try:
i=driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[2]/section[1]/div/div[1]/div/div[1]/div[2]/div/div[2]/div/div/div[2]/img")
video_url.append(i.get_attribute("src"))
except NoSuchElementException:
video_url.append('--')发布于 2022-05-05 19:18:58
实际上,具有嵌入视频名称的图像src属性,使用该唯一的名称,您可以形成视频url。
例如:src="https://i.ytimg.com/vi/YtktfxBFgJU/hqdefault.jpg"
在这里,唯一的代码YtktfxBFgJU可以添加到默认url的后缀中,如下所示:https://www.youtube.com/embed/YtktfxBFgJU,您将得到视频url。
检查这个方法可能会有帮助。
https://stackoverflow.com/questions/72129891
复制相似问题