Getting HTML with Pycurl?

This will send a request and store/print the response body: from StringIO import StringIO import pycurl url = 'google.com/' storage = StringIO() c = pycurl.Curl() c. Setopt(c. URL, url) c.

Setopt(c. WRITEFUNCTION, storage. Write) c.perform() c.close() content = storage.getvalue() print content if you want to store the response headers, use: c.

Setopt(c. HEADERFUNCTION, storage. Write).

Great! That does exactly what I've been looking for. Though, one line is incorrect.It should say storage = StringIO.StringIO().

Otherwise, an error is raised. Regardless, thanks for your help! – Sinthet Jul 2 at 1:26 I think it is correct as-is.

Notice I do 'from StrongIO import StringIO' – Corey Goldberg Jul 2 at 2:06 Ah, that might be it. I checked my source and just imported the entire library. Sorry for the confusion!

– Sinthet Jul 2 at 2:59.

The perform() method executes the html fetch and writes the result to a function you specify. You need to provide a buffer to put the html into and a write function. Usually, this can be accomplished using a StringIO object as follows: import pycurl import StringIO c = pycurl.Curl() c.

Setopt(pycurl. URL, "google.com/") be = StringIO.StringIO() c. Setopt(pycurl.

WRITEFUNCTION, b. Write) c. Setopt(pycurl.

FOLLOWLOCATION, 1) c. Setopt(pycurl. MAXREDIRS, 5) c.perform() html = b.getvalue() You could also use a file or tempfile or anything else that can store data.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions