尝试通过代理查看链接时出现Http错误

时间:2019-05-25 19:38:49

标签: python python-3.x

我正在努力使我的程序正常工作,我昨天才开始研究urllib,我变得非常不知所措,不知道下一步该怎么做,目标是让代理访问用户输入的任何链接,所需的时间(例如https://google.com),每次有3个视图会从一个单独的代理查看该链接3次

尝试使用请求,尝试了我目前使用内联的单个代理尝试的内容。通常只是有点丢了atm

import requests
from pprint import pprint
import urllib.request
import urllib.parse
from http.cookiejar import CookieJar



views = input("How many Views Would You Like")
url = 'https://bitly.com/2Exn9oL'




proxy_host = ['103.194.192.42:43832','188.217.74.95:8118','31.145.137.139:31871'] 


req = urllib.request.Request(
    url, 
    data=None, 
    headers={
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
    }
)


print(views)

for counter in range (0, int(views)):

   req.set_proxy(proxy_host[counter], 'http')

   f = urllib.request.urlopen(req)

print("Finished Clicking Link")


Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
============ RESTART: C:\Users\lauchlan\Desktop\Program\view2.py ============
How many Views Would You Like3
3
Traceback (most recent call last):
  File "C:\Users\lauchlan\Desktop\Program\view2.py", line 35, in <module>
    f = urllib.request.urlopen(req)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 532, in open
    response = meth(req, response)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 570, in error
    return self._call_chain(*args)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
    result = func(*args)
  File "C:\Users\lauchlan\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
>>>

0 个答案:

没有答案