【问题标题】:InvalidSchema(“No connection adapters were found for '%s'” % url)InvalidSchema(“没有为 '%s' 找到连接适配器”% url)
【发布时间】:2019-04-09 05:58:37
【问题描述】:

我正在尝试运行我的抓取工具,但网址有问题。它们看起来像这样://ocdn.eu/pul...

错误信息: raise InvalidSchema("没有为 '%s' 找到连接适配器" % url) requests.exceptions.InvalidSchema:没有找到'/http:///http://...的连接适配器...

在 r = session.get 行引发错误。感谢您的帮助!

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)

【问题讨论】:

    标签: python django http error-handling


    【解决方案1】:

    我改变了这一行:

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

    对于这一行:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-08
      • 1970-01-01
      • 2021-11-29
      相关资源
      最近更新 更多