擅长:python、mysql、java
<p>这个可以很容易地更改为使用任意数量的连接。</p>
<pre><code>MAX_CONNECTIONS = 100 #Number of connections you want to limit it to
# urlsList: Your list of URLs.
results = []
for x in range(1,pages+1, MAX_CONNECTIONS):
rs = (grequests.get(u, stream=False) for u in urlsList[x:x+MAX_CONNECTIONS])
time.sleep(0.2) #You can change this to whatever you see works better.
results.extend(grequests.map(rs)) #The key here is to extend, not append, not insert.
print("Waiting") #Optional, so you see something is done.
</code></pre>