30
28

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 5 years have passed since last update.

認証Proxy環境やBasic認証ページにopen-uriでアクセスする

Posted at

Nokogiriでスクレイピングする時、open-uriを使ってアクセスすることが多い?みたいだけど、例によって閉鎖環境だと一工夫いるのでメモ。

環境変数にhttp_proxyがセットされていれば見に行くっぽいんだけど、自分の環境では見に行ってくれなかった。

Proxyを通す場合

proxy = ["http://hoge.jp:8888", "user", "password"]
open(url, {:proxy_http_basic_authentication => proxy}).read

Basic認証を通す

certs = ["user", "password"]
open(url, {:http_basic_authentication => certs}).read

両方通す

certs = ["user", "password"]
proxy = ["http://hoge.jp:8888", "user", "password"]
open(url, {:http_basic_authentication => certs,
            :proxy_http_basic_authentication => proxy}).read

30
28
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
30
28

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?