Web Scraping Image URL Selenium - PullRequest
       45

Web Scraping Image URL Selenium

0 голосов
/ 27 марта 2020

Я пытаюсь очистить URL-адреса изображений от https://www.billboard.com/charts/hot-100/2019-12-28.

Вот пример (span с class = 'chart-element__image flex - no-shrink')

<span class="chart-element__image flex--no-shrink" style="background-image: url(&quot;https://charts-static.billboard.com/img/1994/12/mariah-carey-99g-all-i-want-for-christmas-is-you-3w0-155x155.jpg&quot;);"></span>

Как вы можете видеть, у span есть свойство 'style', которое показывает значения, отличные от моих результатов скрапа. см. ниже

from selenium import webdriver

def get_selenium_image_list(url):
    """"given a top chart URL returns image list with selenium """
    driver = webdriver.Chrome()  # need to install chrome with specific  driver
    driver.get(url)
    driver.fullscreen_window()
    selenium_query = driver.find_element_by_xpath('//span[@class="chart-element__image flex--no-shrink"]')
    image_list = []
    for element in selenium_query:
        image_list.append(element.get_attribute('style'))
    return image_list
get_selenium_image_list('https://www.billboard.com/charts/hot-100/2019-12-28')

результат:

display: inline-block; height: 0px; width: 0px;
display: inline-block; height: 0px; width: 0px;
display: inline-block; height: 0px; width: 0px;
display: inline-block; height: 0px; width: 0px;
display: inline-block; height: 0px; width: 0px;
display: inline-block; height: 0px; width: 0px;
....

Может кто-нибудь помочь мне понять, почему это происходит? и как решить эту проблему? Спасибо!

...