Home > database >  Selenium: Can't find an element in HTML
Selenium: Can't find an element in HTML

Time:02-17

Hi I am working on the script to automate downloads of videos from this side https://pixabay.com/videos/ I can find a class with href(href is an attribute with URL) but after that Selenium gives me a bug with any error only a result of print(xy.get_atribute("href)) is None: my code:

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.common.by import By
from mutagen.mp3 import MP3
import requests
import time
tag = "city "
while True:
    s = Service(GeckoDriverManager().install())
    driver = webdriver.Firefox(service=s)
    driver.minimize_window()
    
    tester = tag.split()
    print(tester)
    print(len(tester))
    if len(tester) == 2:
        tag = tester[0]   " "   tester[1]
        print(tag)
    print("2 "   tag)
    driver.get("https://pixabay.com/cs/videos/search/"   tag )
    images = driver.find_elements(By.CLASS_NAME, 'item' )
    print(images)
    n = 0
    lenght = 0
    

    for image in images:
        image = image.get_attribute("href")
        print(image)
    break

HTML on the side

<html lang="cs" prefix="og: http://ogp.me/ns#">
<head>.</head> <body  data-new-gr-C-5-check-loaded="14.1050." data-gr-ext-installed>
<noscript>_</noscript> <div id="wrapper"> > <div id="header">...</div> <div id="content" >
::before <div id="search-term" style="display:none">city</div> <div >
<div style="border-bottom:1px solid #f0f1f4"> </div> <div style="background:#e8eaec" >.</div> <div style="background: #f6f5fa"> <div style="max-width: 1824px;padding: 10px 3px 20px;margin: auto">
<h1 style="font-size: 13px;color:#bbb;margin:0 19px; position:relative;top:2px">70 videa zdarma z city</h1> <div >...</div> <div > flex <div  style="flex-basis: 355.55555555555554px; flex-grow: 1.7777777777777777; flex-shrink: 1.7777777777777777; max-width: 622.2222222222222px"> <div  style="padding-top: 56.25%"> <div > <div itemscope itemtype="schema.org/videoobject"  data-w="1920" data-h="1980">
<meta itemprop="license" content="https://creativecommons.org/licenses/publicdomain/"> <meta itemprop="contentUrl" content="//player.vimeo.com/external/142621375.mobile.mp4?s=e9a3c9616798b6f3de74d579ea8314acc75fad72&profile_id=116"> <meta itemprop="thumbnailUrl" content="https://i.vimeocdn.com/video/539965294-5d28c2680682aa5173e86fa74acb94671783ba7e2dc2892682e897c8a158af75-d_640x360.jpg"> <meta itemprop="name" content="New York City, Manhattan, Lidé"> <meta itemprop="description" content="New York City, Manhattan, Lidé, Auta, Rozcestí, Amerika"> <meta itemprop="duration" content="TM145"> <meta itemprop="uploadDate" content="2022-02-16"> <a href="/cs/videos/new-york-city-manhattan-lidC3           
  • Related