前提・実現したいこと
https://teratail.com/questions/210140
の続きです.
引き続き初歩的質問ですがよろしくお願いいたします.
ジャミラの画像を取ってきたいです.
発生している問題・エラーメッセージ
取ってきた画像が文字化けしています.
該当のソースコード
from
1from selenium.webdriver.common.keys import Keys 2from bs4 import BeautifulSoup 3import requests 4import os 5import time 6 7driver = webdriver.Chrome("C:/Users/***/chromedriver") 8 9driver.get("https://search.yahoo.co.jp/image") 10driver.find_element_by_name("p").send_keys("ジャミラ",Keys.ENTER) 11driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 12time.sleep(5) 13driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 14time.sleep(5) 15driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 16time.sleep(5) 17driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 18time.sleep(5) 19driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 20time.sleep(10) 21driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 22time.sleep(5) 23driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 24time.sleep(5) 25 26# 現在のページのurlを変数に入れる 27current_url = driver.current_url 28html = driver.page_source 29bs = BeautifulSoup(html, "lxml") 30images = bs.find_all("img") 31# imgフォルダの作成 32os.makedirs("img") 33# 取得した画像をループして保存 34for i,img in enumerate(images, start=1): 35 src = img.get("src") 36 responce = html.encode() 37 with open("img/" + "{}.jpg".format(i), "wb") as f: 38 f.write(responce) 39 40driver.quit() 41
補足情報(FW/ツールのバージョンなど)
jupyter notebookで書いています.
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/09/05 08:09
2019/09/05 08:10
2019/09/05 08:13
2019/09/05 08:14
2019/09/05 08:28
2019/09/05 08:36
2019/09/05 08:39
2019/09/05 08:41
2019/09/05 11:18