import urllib.request ## urllib module is used to send request and receive response from a server. It can used to get html / JSON / XML data from an api.
webData = request.urlopen("http://www.google.com") ## It opens a connection to google.com and returns an object of class http.client.HTTPResponse
.read()
return the HTML data of the webpage.
.getcode()
returns the status code of the connection establishment.
from html.parser import HTMLParser
class MyHTMLParser(HTMLParser):
def error(self, message):
pass
parser = MyHTMLParser()
f = open("check.html")
if f.mode == 'r': # file successfully opened
contents = f.read()
parser.feed(contents)
import json
json_data = json.loads(response)
import xml.dom.minidom
doc = minidom.parse("check.xml")