Not quite. Creating a Request
object does not actually send the request, and Request objects have no Read()
method. (Also: read()
is lowercase.) All you need to do is pass the Request
as the first argument to urlopen()
and that will give you your response.
import urllib2
request = urllib2.Request("http://www.google.com", headers={"Accept" : "text/html"})
contents = urllib2.urlopen(request).read()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…