Image-Downloader icon indicating copy to clipboard operation
Image-Downloader copied to clipboard

Error when downloading pics using chrome

Open qiuzhewei opened this issue 3 years ago • 2 comments

Hi, Following error occcurs when I try to run the script.

selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

Any help will be appreciate!

qiuzhewei avatar Aug 03 '21 04:08 qiuzhewei

You need to install the chrome browser in your operating system in the first place to use the selenium package.

caop-kie avatar May 27 '22 02:05 caop-kie

For anyone still having this issue, the problem lies within the regex for parsing the image URL. It gets extra junk in there which breaks the image link. To fix the code, modify google_image_url_from_webpage function in crawler.py to this:

# (line 121)

image_elements = driver.find_elements(By.CLASS_NAME, "islib")
    image_urls = list()
    url_pattern = r"imgurl=\S*?&" # explanation: \S -> match any whitespace character
                                      #                  *? -> match previous token \S between 0 and unlimited times and do so lazily, aka match until the first & and not the last one

    for image_element in image_elements[:max_number]:
        outer_html = image_element.get_attribute("outerHTML")
        re_group = re.search(url_pattern, outer_html)
        if re_group is not None:
            image_url = unquote(re_group.group()[len("imgurl=") : -len("&")])
            image_urls.append(image_url)
    return image_urls

madiskoivopuu avatar May 16 '23 15:05 madiskoivopuu