首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从网站的多页中抓取视频url

从网站的多页中抓取视频url
EN

Stack Overflow用户
提问于 2022-05-05 15:36:20
回答 1查看 63关注 0票数 -1

我在用硒刮擦。我想刮所有的视频网址,是存在于626产品在25页。但是在提取url时,它给了我图像文件源缩略图的href链接。

代码语言:javascript
复制
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('--')
EN

回答 1

Stack Overflow用户

发布于 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。

检查这个方法可能会有帮助。

代码语言:javascript
复制
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72129891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档