Show Menu
Cheatography

Python Modules Cheatsheet Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Beatif­ulSoup (parse a website)

from bs4 import Beauti­fulSoup
import module
soup = Beauti­ful­Sou­p(html, "­lmx­l")
create new object
S = soup.f­ind­('a')
finds first <a> tags
S_all = soup.f­ind­_al­l('a')
finds all <a> tags, saves as list
S_list = soup.f­ind­_al­l(['a', 'b'])
finds all <a> and <b> tags
S_all_tags = soup.f­ind­_al­l(True)
finds all tags <> and no text

Requests

import requests
import module
S = reques­ts.g­et­(url)
get html
S.content
url content in object form
 

QT (Graphical Interface)

 

Selenium (automated web experi­ence)

import selenium
import module

JSON (write or read from JSON file)

import json
import module
J = json.d­ump­s(data)
saves dictionary to JSON format
J_sorted = json.d­ump­s(data, sort_keys = True)
saves dictionary to JSON format but in the order

Scrapy (web crawler)