Created
December 14, 2018 09:22
-
-
Save chidindu-ogbonna/9d8d53d4da223de1a9db6150c6c7341c to your computer and use it in GitHub Desktop.
Basic API example for https://cymath.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
DISCLAIMER | |
I am not responsible for any actions or usage of this API, the api clearly states | |
"Restricted Access. We may pursue legal actions over unauthorized uses of this API." | |
This script is for educational purposes ONLY | |
""" | |
import requests | |
query = input("Your question:" ).replace(" ", "") | |
headers = { | |
"DNT": "1", | |
"Accept-Encoding": "gzip, deflate, br", | |
"Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8", | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.42 Safari/537.36", | |
"Accept": "*/*", | |
"Referer": "https://www.cymath.com/answer?q={}".format(query), | |
"Connection": "keep-alive", | |
} | |
params = { | |
"q" : query, | |
} | |
r = requests.get("https://www.cymath.com/answer", params=params) | |
cookies = { | |
"PHPSESSID": r.headers["Set-Cookie"].split("=")[1].split(";")[0], | |
} | |
params["lang"] = "en" | |
response = requests.get("https://www.cymath.com/ajax/get_steps.php", headers=headers, params=params, cookies=cookies) | |
print(response.text) | |
# This returns the HTML elements for the script, this can be parsed using lxml, beautifulsoup4, scrapy, and more. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment