requests.get

Date: May 11th 2016
Last updated: May 11th 2016

Collecting data from the web can be done a few ways. This example uses the request module.

import requests

web_request = requests.get('http://www.pythonforbeginners.com')
web_request.text

# Output
"""
'<!DOCTYPE html>\n<html lang="en-US" prefix="og:
http://ogp.me/ns#">\n    <head>\n        <meta
charset="UTF-8" />\n        <meta name="viewport"
content="width=device-width" />\n        <title>
Pythonforbeginners.com - Learn Python by Example
</title>\n        <link rel="profile" 
href="http://gmpg.org/xfn/11" />\n        
<link rel="canonical"
href="http://www.pythonforbeginners.com/" />    
\n
"""

pretty print the request

from pprint import pprint
pprint(web_request.text[1:380])

# Output
('!DOCTYPE html>\n'
 '<html lang="en-US" prefix="og: http://ogp.me/ns#">\n'
 '    <head>\n'
 '        <meta charset="UTF-8" />\n'
 '        <meta name="viewport" content="width=device-width" />\n'
 '        <title> Pythonforbeginners.com - Learn Python by Example </title>\n'
 '        <link rel="profile" href="http://gmpg.org/xfn/11" />\n'
 '        <link rel="canonical" href="http://www.pythonforbeginners.com/" ')

results matching ""

    No results matching ""