<p>Hi,<br>it is my first time use twisted .<br>i want to use the a function pass a url then get the web page<br>the code as :</p>
<div>// <strong>some code call getPage</strong></div>
<div> </div>
<div><em>while id <= 10000000:<br> getPage("</em><a href="http://www.mywebsite.com/News.aspx?ID="+str(id"><em>http://www.mywebsite.com/News.aspx?ID="+str(id</em></a><em>))<br> id += 1<br>
</em>//******************************************</div>
<p><strong>the getPage is definition in twisted.web.client</strong></p>
<p><em>def getPage(url, contextFactory=None, *args, **kwargs):<br> """Download a web page as a string.</em></p>
<p><em> Download a page. Return a deferred, which will callback with a<br> page (as a string) or errback with a description of the error.</em></p>
<p><em> See HTTPClientFactory to see what extra args can be passed.<br> """<br> scheme, host, port, path = _parse(url)<br> factory = HTTPClientFactory(url, *args, **kwargs)<br> if scheme == 'https':
<br> from twisted.internet import ssl<br> if contextFactory is None:<br> contextFactory = ssl.ClientContextFactory()<br> reactor.connectSSL(host, port, factory, contextFactory)<br> else:
<br> reactor.connectTCP(host, port, factory)<br> return factory.deferred</em> <br>-------------------------------------------------------------------------------- <br><strong>Question:<br></strong>for the getPage function,if use it to get 10000 page ,it would open/close
<br>connection 10000 times,it is a very large cost。<br>So ,any body can give me some advice?creat a class inherit from HTTPPageGetter(as a protocol class) <br>or HTTPClientFactory?</p>