0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【 Python】InvalidSchema: No connection adapters were found for[画像URL]の対処方法

Posted at

自分用のメモに記載しているので、文章はかなり雑です。

python.py
import requests as req

#まずは1枚の画像を取得するところから
test_url="https://papimo.jp/h/00031715/hit/view/605"
soup = BeautifulSoup(html, "html.parser")

img_url=[]
img_tags=soup.find("table",attrs={"class":"graph-some"}).find_all("img")[-1]
img_tag=img_tags.get("src")
img_url.append(img_tag)

reqData1 = req.get(img_url)
with open('/content/gdrive/MyDrive/Colab Notebooks/iland_img/605.png', 'wb') as file:
  file.write(reqData1.content)

テスト用でとりあえず1つダウンロードしたかっただけなので、for文で回す必要がないと思っていたけども。
実際実行してみると

python.py
InvalidSchema: No connection adapters were found for[画像URL]

というエラーが発生。
問題だったのはreq.getにリストをそのまま渡してしまっていたこと。
普通にfor文で回したら、解決

python.py
import requests as req

#まずは1枚の画像を取得するところから
test_url="https://papimo.jp/h/00031715/hit/view/605"
soup = BeautifulSoup(html, "html.parser")

img_url=[]
img_tags=soup.find("table",attrs={"class":"graph-some"}).find_all("img")[-1]
img_tag=img_tags.get("src")
img_url.append(img_tag)

for i_url in img_url:
  reqData1 = req.get(i_url)
  with open('/content/gdrive/MyDrive/Colab Notebooks/iland_img/605.png', 'wb') as file:
      file.write(reqData1.content)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?