2

I'm tyring to download memes given a url from 9gag. I've been using the same code below for a while now and everything was working good. Recently since few weeks it's been throwing an error and I can't understand how to resolve it.

    from urllib import request
    import undetected_chromedriver as UC
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.service import Service
    from undetected_chromedriver._compat import ChromeDriverManager

    post = "az28zPm" #this 6 digit value is the unique id for the meme
    options = Options()
    options.headless = True
    url = "https://9gag.com/gag/" + post
    driver = uc.Chrome(service=Service(ChromeDriverManager().install()), options=options)
    driver.get(url)
    if not os.path.isdir("Attachments/" + post): os.makedirs("Attachments/" + post)
    try:
        video_link = driver.find_element(By.XPATH, '//*[@id]/div[2]/div[1]/a/div/video/source[1]').get_attribute('src')
        request.urlretrieve(video_link, "Attachments/" + post + "/" + "Meme.mp4")
    except:
        image_link = driver.find_element(By.XPATH, '//*[@id]/div[2]/div[1]/a/div/picture/img').get_attribute('src')
        request.urlretrieve(image_link, "Attachments/" + post + "/" + "Meme.jpg")

The following is the error:

driver = uc.Chrome(service=Service(ChromeDriverManager().install()), options=options)
TypeError: Can't instantiate abstract class Service with abstract methods command_line_args

I took the XPATH from the 9gag website for the image and video respectively and they were working fine till now. Please help me if I have to change anything and try. I can also go with any completely new approach that you might suggest.

Many Thanks.

0 Answers0