LoginSignup
8
3

More than 5 years have passed since last update.

scrapy経由でダウンロードした結果が英語になってしまう時の対処

Last updated at Posted at 2017-02-06

ブラウザでページを見ると日本語なのに、scrapy経由でダウンロードすると英語のページがダウンロードされてしまうことがあります。
これはscrapyがwebサーバーにリクエストを投げる時のAccept-Lauguageがデフォルトでenなためなので、以下の内容をsettings.pyに書くことで日本語ページをリクエストすることができます。

DEFAULT_REQUEST_HEADERS = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'ja,en-US;q=0.8,en;q=0.6',
}

参考:
https://doc.scrapy.org/en/latest/topics/settings.html#std:setting-DEFAULT_REQUEST_HEADERS

8
3
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
8
3