Difference between revisions of "Urllib"

From wikieduonline
Jump to navigation Jump to search
(Created page with " urllib.request * {{Python}}")
 
Line 2: Line 2:
  
  
 +
Adding [[HTTP headers]]:
 +
import urllib.request
 +
req = urllib.request.Request('http://www.example.com/')
 +
req.add_header('Referer', 'http://www.python.org/')
 +
# Customize the default User-Agent header value:
 +
req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
 +
r = urllib.request.urlopen(req)
  
  
 
* {{Python}}
 
* {{Python}}

Revision as of 14:05, 10 November 2022

urllib.request


Adding HTTP headers:

import urllib.request
req = urllib.request.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
# Customize the default User-Agent header value:
req.add_header('User-Agent', 'urllib-example/0.1 (Contact: . . .)')
r = urllib.request.urlopen(req)


Advertising: