Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x bs4和请求代理脚本错误_Python 3.x_Proxy_Beautifulsoup_Python Requests_Urllib3 - Fatal编程技术网

Python 3.x bs4和请求代理脚本错误

Python 3.x bs4和请求代理脚本错误,python-3.x,proxy,beautifulsoup,python-requests,urllib3,Python 3.x,Proxy,Beautifulsoup,Python Requests,Urllib3,我目前正在编写一个脚本,从supremenewyork.com获取信息 我使用的这个代理脚本正在“sorta”工作以前和现在它根本不工作,自从我在我的计算机上看到这个叫做urllib3的东西后,我认为它没用,所以我卸载了它,然后我尝试再次运行我的代理脚本,我得到了一个关于urllib3的错误,所以我很快重新安装了urllib3,但此后我的脚本再也不工作了。。。 这是我的剧本: import requests from bs4 import BeautifulSoup UK_Proxy1 = in

我目前正在编写一个脚本,从supremenewyork.com获取信息 我使用的这个代理脚本正在“sorta”工作以前和现在它根本不工作,自从我在我的计算机上看到这个叫做urllib3的东西后,我认为它没用,所以我卸载了它,然后我尝试再次运行我的代理脚本,我得到了一个关于urllib3的错误,所以我很快重新安装了urllib3,但此后我的脚本再也不工作了。。。 这是我的剧本:

import requests
from bs4 import BeautifulSoup
UK_Proxy1 = input('UK http Proxy1: ')
UK_Proxy2 = input('UK http Proxy2: ')

proxies = {
 'http': 'http://' + UK_Proxy1 + '',
   'https': 'http://' + UK_Proxy2 + '',

}

categorys = ['jackets','shirts','tops_sweaters','sweatshirts','pants','shorts','t-shirts','hats','bags','accessories','shoes','skate']
catNumb = 0

for cat in categorys:
    catStr = str(categorys[catNumb])
    cUrl = 'http://www.supremenewyork.com/shop/all/' + catStr
    proxy_script = requests.get(cUrl, proxies=proxies).text
    bSoup = BeautifulSoup(proxy_script, 'lxml')
    print('\n*******************"'+ catStr.upper() + '"*******************\n')
catNumb += 1
for item in bSoup.find_all('div', class_='inner-article'):
    url = item.a['href']
    alt = item.find('img')['alt']
    req = requests.get('http://www.supremenewyork.com' + url)
    item_soup = BeautifulSoup(req.text, 'lxml')
    name = item_soup.find('h1', itemprop='name').text
    style = item_soup.find('p', itemprop='model').text
    print (alt + ' --- ' + name + ' --- ' + style)
当我运行这个脚本并输入一个uk代理时,我得到了这个错误

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
在处理上述异常期间,发生了另一个异常:

  Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
`Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred: (same error as above and continues for a bit)

 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max retries exceeded with url: http://www.supremenewyork.com/shop/all/jackets (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)))
在处理上述异常期间,发生了另一个异常:

  Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 141, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/socket.py", line 745, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
`Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 166, in connect
    conn = self._new_conn()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 150, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known

During handling of the above exception, another exception occurred: (same error as above and continues for a bit)

 File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 639, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/util/retry.py", line 388, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='109.108.153.29\t', port=80): Max retries exceeded with url: http://www.supremenewyork.com/shop/all/jackets (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x112d10eb8>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)))
`回溯(最近一次呼叫最后一次):
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/connectionpool.py”,urlopen中第601行
分块=分块)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/connectionpool.py”,第357行,在请求中
conn.request(方法,url,**httplib\u request\u kw)
请求中的文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1239行
self.\u发送\u请求(方法、url、正文、标题、编码\u分块)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1285行,在发送请求中
self.endheaders(body,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1234行,在endheaders中
self.\u发送\u输出(消息体,encode\u chunked=encode\u chunked)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第1026行,在发送输出中
self.send(msg)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py”,第964行,在send中
self.connect()
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/connection.py”,第166行,在connect中
conn=自我。_new_conn()
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/connection.py”,第150行,位于康涅狄格州的新州
self,“无法建立新连接:%s”%e)
urllib3.exceptions.NewConnectionError::未能建立新连接:[Errno 8]提供了节点名或servname,或者未知
在处理上述异常期间,发生了另一个异常:(与上述错误相同,并持续一段时间)
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/connectionpool.py”,第639行,在urlopen中
_stacktrace=sys.exc_info()[2])
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site packages/urllib3/util/retry.py”,第388行,增量
引发MaxRetryError(_池、url、错误或响应错误(原因))
urllib3.exceptions.MaxRetryError:HTTPConnectionPool(host='109.108.153.29\t',port=80):url超过了最大重试次数:http://www.supremenewyork.com/shop/all/jackets (由ProxyError('无法连接到代理')、NewConnectionError(':未能建立新连接:[Errno 8]节点名或提供的servname,或未知',)引起)
我已经尝试了几种不同的代理,但没有一种有效
有人能帮我一下吗我真的很感激这是答案的底线, 它无法工作,因为代理未连接到

你所要做的就是为它提供一个工作代理和一个端口,如果你的计算机没有internet连接,它会给你同样的错误,但是因为你在StackOverflow上,我假设你有

urllib3.exceptions.MaxRetryError:HTTPConnectionPool(host='109.108.153.29\t',port=80):url超过了最大重试次数:http://www.supremenewyork.com/shop/all/jackets (由ProxyError('无法连接到代理')、NewConnectionError(':未能建立新连接:[Errno 8]节点名或提供的servname,或未知',)引起)
下面是我们如何修复它的: 我们不需要我们使用一个有效的代理并为其提供一个端口, 您可以在此网站上获取代理列表,并使用
random.choice()
始终选择其他代理。
http://www.gatherproxy.com/

import requests
from bs4 import BeautifulSoup
UK_Proxy1 = '173.212.202.65:80'
# UK_Proxy2 = input('UK http Proxy2: ')

proxies = {
 'http': 'http://' + UK_Proxy1,
   'https': 'https://' + UK_Proxy1
}

categorys = ['jackets','shirts','tops_sweaters','sweatshirts','pants','shorts','t-shirts','hats','bags','accessories','shoes','skate']
catNumb = 0

for cat in categorys:
    catStr = str(categorys[catNumb])
    cUrl = 'http://www.supremenewyork.com/shop/all/' + catStr
    proxy_script = requests.get(cUrl, proxies=proxies).text
    bSoup = BeautifulSoup(proxy_script, 'lxml')
    print('\n*******************"'+ catStr.upper() + '"*******************\n')
catNumb += 1
for item in bSoup.find_all('div', class_='inner-article'):
    url = item.a['href']
    alt = item.find('img')['alt']
    req = requests.get('http://www.supremenewyork.com' + url)
    item_soup = BeautifulSoup(req.text, 'lxml')
    name = item_soup.find('h1', itemprop='name').text
    style = item_soup.find('p', itemprop='model').text
    print (alt + ' --- ' + name + ' --- ' + style)

谢谢你的回答!因此,基本上,我会使用另一个bs4请求脚本将代理+端口拉到一起,并将其放入UK_Proxy1?@Elivir Muslic。我已经通过键入ip地址进行了多次测试:端口大多数情况下,我都会遇到相同的错误,但有时我会从supreme new york的DIFF网站上拉取信息,从而得到我想要的结果文本被置乱,这不再使其成为文本,我猜,因此我得到的属性不是代理的文本=代理)。textthing@bobo加扰文本可能是因为代理无效(即,存在仅用于广告其产品的代理)您可以从此网站或其他网站(已更新)中提取代理列表,也可以提供自己的代理列表。