【发布时间】:2018-06-22 17:56:07
【问题描述】:
我正在尝试构建一个机器人,它将废弃已购买域的购买历史记录。到目前为止,我能够从 csv 文件中提取域并将它们存储到一个列表中(PS:有 10k 个域)。当我试图与他们一起废弃网站时,问题就出现了。我已经尝试使用两个域来执行此操作,并且效果很好。有谁知道这是什么错误以及我该如何解决?非常感谢您。
我的代码:
datafile = open('/Users/.../Documents/Domains.csv', 'r')
myreader = csv.reader(datafile, delimiter=";",)
domains = []
for row in myreader:
domains.append(row[1])
del domains[0]
print("The Domains have been stored into a list")
nmb_sells_record = 0
def result_catcher(domains,queue):
template_url = "https://namebio.com/{}".format(domain)
get = requests.get(template_url)
results = get.text
last_sold = results[results.index("last sold for ")+15:results.index(" on 2")].replace(",","")
last_sold = int(last_sold)
if not "No historical sales found." in results:
sold_history = results[results.index("<span class=\"label label-success\">"):results.index(" USD</span> on <span class=\"label")]
queue.put(results)
#domains = ["chosen.com","koalas.com"]
queues = {}
nmb=0
for x in range(len(domains)):
new_queue = "queue{}".format(nmb)
queues[new_queue] = queue.Queue()
nmb += 1
count = 0
for domain in domains:
for queue in queues:
t = threading.Thread(target=result_catcher, args=(domain,queues[queue]))
t.start()
print("The Requests were all sent, now they are beeing analysed")
for queue in queues:
response_domain = queues[queue].get()
nmb_sells_record = response_domain.count("for $") + response_domain.count("USD")
print("The Bot has recorded {} domain sells".format(nmb_sells_record))
我的代码输出:
Exception in thread Thread-345:
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 743, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
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 346, in _make_request
self._validate_conn(conn)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connectionpool.py", line 850, in _validate_conn
conn.connect()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/urllib3/connection.py", line 284, 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.VerifiedHTTPSConnection object at 0x115a55a20>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
【问题讨论】:
标签: python multithreading csv web-scraping python-multithreading