Python API Querying and Scrapping

Updated at
API QueryingCommand
Import moduleimport requests
GET Requestrequests.get(url, params={}, headers={})
POST Requestrequests.post(url, json=payload)
PUT/PATCH Requestrequests.patch(url, json=payload)
DELETE Requestrequests.delete(url)
Statusresponse.status_code
Content in Stringresponse.content
Request/Response in JSONresponse.json()
Content-Typeresponse.headers['content-type']
ScrappingCommand
Import modulefrom bs4 import BeautifulSoup
Initialize the parserparser = BeautifulSoup(response_content, 'html.parser')
Get the body tagparser.body
Get the inside text of a tagparser.head.title.text
Find specific tagsparser.body.find_all('p', id='i', class_='c')
Find all tags by selectorsparser.body.select('.c')
RegexCommand
Python moduleimport re | re.search(pattern, string) | re.findall(patttern, string)
Regex pattern checks.str.contains(r'', na=False, flags=re.IGNORECASE) | IGNORECASE = I
Regex pattern extracts.str.extract(r'', expand=True, flags) | expand returns df
Regex pattern replaces.str.replace(r'', replace, flags)
Regex all patterns extracts.str.extractall(r'')