行っていたこと
- pythonのrequestsを使って複数のURLをチェック(URLが死んでいないか)
- URLの補強
問題
問題1 : 脆弱性に該当するSSL通信
エラー内容
<urlopen error [SSL: DH_KEY_TOO_SMALL] dh key too small (_ssl.c:1091)>
requests.get(url, verify = False)
verify = False
をつけるとセキュリティのレベルを下げてくれるらしい
しかし、エラーとしてではないけど、Warningがめちゃ出る
import urllib3
from urllib3.exceptions import InsecureRequestWarning
urllib3.disable_warnings(InsecureRequestWarning)
問題2 : URLは開けるはずなのに、403で返ってくる
requestsでgetすると403で返ってきてしまう
・・・URLを踏むとUser Agentに応じてステータスコードが異なるように設定されている
USER_AGENT = {"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 Mobile/14G60 Safari/602.1"}
response = requests.get(url, headers=USER_AGENT, verify = False)
print(response.status_code)
headers=USER_AGENT
iPhoneで入っていると認識させる必要がある
(pythonのrequestsのデフォルトがpython-requests
)
URLの補強
aタグのhrefに/company
などが検出され、踏んでもページが発見できない
from urllib.parse import urlparse
parsed_url = urlparse(url)
print(parsed_url.scheme) # http or https
print(parsed_url.netloc) # ドメイン
/company
と同一ドメインの時に上記のコードを使うことで、URLを補強して作ることができる!
最後に
大量のURLを叩くほど、見たことないURLエラーが出たので備忘録としても記載しました。
URLのエラ−って沢山あるんだなぁと知りました。
また、新しいエラーがあったら追記します。
参考文献
urllibでも同じようなことができるので、使ってみました