简体   繁体   中英

InvalidSchema(“No connection adapters were found for '%s'” % url)

I'm trying to run my scraper, but there is a problem with urls. They are looking like this: //ocdn.eu/pul...

Error message: raise InvalidSchema("No connection adapters were found for '%s'" % url) requests.exceptions.InvalidSchema: No connection adapters were found for '/ http:///http:// ...

Error raise at r = session.get line. Thanks for help!

for post in posts:
    title = post.find('span', {'class': 'title'}).get_text()
    link = post.find("a")['href']
    image_source = post.find('img')['src']
    image_source_solved = "http://".join(image_source)

    # stackoverflow solution

    media_root = '/Users/mat/Desktop/jspython/just django/dashboard/media_root'
    if not image_source.startswith(("data:image", "javascript")):
        local_filename = image_source.split('/')[-1].split("?")[0]
        r = session.get(image_source_solved, stream=True, verify=False)
        with open(local_filename, 'wb') as f:
            for chunk in r.iter_content(chunk_size=1024):
                f.write(chunk)

        current_image_absolute_path = os.path.abspath(local_filename)
        shutil.move(current_image_absolute_path, media_root)

I changed this line:

image_source_solved = "http://".join(image_source)

for this line:

image_source_solved = "http:{}".format(image_source)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM