urlopen Returning Redirect Error for Valid Links

后端 未结 3 600
[愿得一人]
[愿得一人] 2021-01-06 03:57

I\'m building a broken link checker in python, and it\'s becoming a chore building the logic for correctly identifying links that do not resolve when visited with a browser.

3条回答
  •  庸人自扰
    2021-01-06 04:38

    I concur with the comments in the 1st answer and it wasn't working for me (I was getting some encoded/compressed byte data, nothing readable)

    The link mentioned used urllib2. It also works with urllib in python 3.7 as follow:

    from urllib.request import build_opener, HTTPCookieProcessor
    opener = build_opener(HTTPCookieProcessor())
    response = opener.open('http://www.bad.org.uk')
    print response.read()
    

提交回复
热议问题