URLを変更して画像をダウンロードしようとしましたが、エラーが発生しました。Pythonは、変数を変更することで画像をダウンロードします
url_image="http://www.joblo.com/timthumb.php?src=/posters/images/full/"+str(title_2)+"-poster1.jpg&h=333&w=225"
user_agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)'
headers = {'User-Agent': user_agent}
req = urllib.request.Request(url_image, None, headers)
print(url_image)
#image, h = urllib.request.urlretrieve(url_image)
with urllib.request.urlopen(req) as response:
the_page = response.read()
#print (the_page)
with open('poster.jpg', 'wb') as f:
f.write(the_page)
トレースバック(最新の呼び出しの最後): ファイル "C:\ Users \ユーザールーク\デスクトップ\スクレーパー\イメージャfinder.py" urllib.request.urlopen(REQ)と では、ライン97、などレスポンス: ファイル "C:\ Users \ luke \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py"、行162、urlopen return opener.open(url、data、timeout) ファイル "C:¥Users¥luke¥AppData¥Local¥Programs¥Python¥Python35-32¥lib¥urllib¥request.py"、行465、オープン中 応答= self._open(req、data) ファイル " C:\ Users \ luke \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py "、行483、_open '_open'、req) ファイル "C:¥Users¥luke¥AppData¥Local¥Programs¥Python¥Python35-32¥lib¥urllib¥request.py"、行443、_call_chain 結果= func(* args ) http_openのファイル "C:¥Users¥luke¥AppData¥Local¥Programs¥Python¥Python35-32¥lib¥urllib¥request.py"、1268行、 return self.do_open(http.client.HTTPConnection、req ) do_openのファイル "C:\ Users \ luke \ AppData \ Local \ Programs \ Python \ Python35-32 \ lib \ urllib \ request.py" 1243行do_open内 r = h.getresponse() ファイル "C: \ Users \ユーザールーク\のAppData \ローカル:C "のGetResponse response.begin() ファイルでは、行1174、" \ Users \ユーザールーク\のAppData \ローカル\プログラム\ Pythonの\ Python35-32 \ libに\ HTTP \ client.py \ Program \ Python \ Python35-32 \ lib \ http \ client.py "、行282、begin バージョン、ステータス、理由= self._read_status() ファイル "C:\ Users \ユーザールーク\のAppData \ローカル\プログラム\ Pythonの\ Python35-32 \ libに\ HTTP \ client.py" _read_status レイズでは、ライン264、 BadStatusLine(行) http.client.BadStatusLine:
をurllib2の使用方法を扱ういくつかの他の質問をグーグルその場合には、何らかの理由でWindows上でMozillaを使用していますか?)。また、title_2が何であるかわからない。奇数の文字やスペースがある場合は、エンコードする必要があります。 – Fhaab
はちょうどタイトル2のために10-クローバーフィールドレーンを使用してヘッダーなしで同じエラーメッセージがアップします – spark