Skip to content

Commit d346d35

Browse files
Readme
1 parent d870097 commit d346d35

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# This scrape some math solver websites.
2+
3+
1. https://www.cymath.com/
4+
2. https://www.wolframalpha.com/
5+
3. https://www.symbolab.com/
6+
7+
'''
8+
"""
9+
%2B = +
10+
%3D = =
11+
%2F = /
12+
13+
Symbolab:
14+
sin = /sin
15+
(=\left(
16+
)=\right)
17+
* = \cdot
18+
19+
20+
\=\frac{num}{denom}
21+
22+
23+
"""
24+
25+
import requests
26+
from bs4 import BeautifulSoup
27+
from selenium import webdriver
28+
29+
GETINPUT = True
30+
31+
uinput = "1+1"
32+
33+
if(GETINPUT == True):
34+
uinput = input("Enter Input: ")
35+
36+
37+
38+
39+
runWOLFRAM = True
40+
runCYMATH = True
41+
runSYMBOLAB = True
42+
43+
44+
browser = webdriver.PhantomJS(executable_path='C:\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe')
45+
46+
47+
def formaturlexpr(expr, urlbase, site):
48+
# sin(3*x)%2B4%3D4-5*pi
49+
if (site == "wolfram" or site == "cymath"):
50+
eu1 = expr.replace('+','%2B')
51+
eu2 = eu1.replace('=','%3D')
52+
eu3 = eu2.replace('/','%2F')
53+
endurl = eu3
54+
finalurl = urlbase + endurl
55+
# print(finalurl)
56+
return finalurl
57+
elif (site == "symbolab"):
58+
eu1 = expr.replace('+','%2B')
59+
eu2 = eu1.replace('=','%3D')
60+
eu3 = eu2.replace('/','%2F')
61+
eu4 = eu3.replace('sin','/sin')
62+
eu5 = eu4.replace('(','\\left(')
63+
eu6 = eu5.replace(')','\\right)')
64+
eu7 = eu6.replace('*','\\cdot')
65+
endurl = eu7
66+
finalurl = urlbase + endurl
67+
# print(finalurl)
68+
return finalurl
69+
70+
71+
72+
site = "https://www.wolframalpha.com/input/?i="
73+
74+
75+
def WolframFunction():
76+
sitedemo = "https://www.wolframalpha.com/input/?i=sin(x)%3D24"
77+
site = formaturlexpr(uinput, "https://www.wolframalpha.com/input/?i=", "wolfram")
78+
79+
80+
browser.set_window_size(1120, 550)
81+
browser.get(site)
82+
browser.save_screenshot('wolframscreenshot.png')
83+
84+
html = browser.page_source
85+
soup = BeautifulSoup(html, 'html.parser')
86+
87+
SymbolicSolution = soup.find(id="SymbolicSolution")
88+
imglist = SymbolicSolution.find_all('img', class_='ng-isolate-scope', alt=True)
89+
90+
print("WOLFRAMALPHA")
91+
92+
for item in imglist:
93+
# print(item.get_text())
94+
print(item['alt'])
95+
96+
97+
98+
99+
def CymathFunction():
100+
sitedemo = "https://www.cymath.com/answer?q=sin(x)%3D24"
101+
site = formaturlexpr(uinput, "https://www.cymath.com/answer?q=", "cymath")
102+
103+
104+
browser.set_window_size(1120, 550)
105+
browser.get(site)
106+
browser.save_screenshot('cymathscreenshot.png')
107+
108+
109+
html = browser.page_source
110+
soup = BeautifulSoup(html, 'html.parser')
111+
112+
113+
stepsdivlist = soup.find_all(id="steps_div")
114+
itnlist = soup.find_all(class_='itn')
115+
katexlist = soup.find_all(class_='katex')
116+
listmord = soup.find_all(class_='mord mathrm')
117+
sollist = soup.findChildren(class_='base textstyle uncramped')
118+
hiddenanswers = soup.find(id="answer")
119+
120+
print("CYMATH")
121+
122+
hiddenanswertext = hiddenanswers.get_text()
123+
# print(hiddenanswertext)
124+
hat1 = hiddenanswertext.replace('),sequence(',' & ')
125+
hat2 = hat1.replace('sequence(', ' ')
126+
hat3 = hat2[:-1]
127+
hat4 = hat3.replace('PI', 'π')
128+
hiddenanswertext = hat4
129+
print(hiddenanswertext)
130+
131+
132+
133+
def SymbolabFunction():
134+
sitedemo = "https://www.symbolab.com/solver/step-by-step/sin%5Cleft(x%5Cright)%3D24"
135+
site = "https://www.symbolab.com/solver/step-by-step/sin%5Cleft(x%5Cright)%3D24"
136+
137+
138+
browser.set_window_size(1120, 550)
139+
browser.get(site)
140+
browser.save_screenshot('symbolabscreenshot.png')
141+
142+
143+
144+
html = browser.page_source
145+
soup = BeautifulSoup(html, 'html.parser')
146+
147+
148+
selectablelist = soup.find_all(class_='selectable')
149+
solutionslist = soup.find_all(class_='solution_step_list_item')
150+
151+
# print(solutionsteplist)
152+
153+
print("SYMBOLAB")
154+
155+
for item in solutionslist:
156+
157+
print(item.get_text())
158+
159+
160+
161+
162+
163+
164+
if runWOLFRAM == True:
165+
try:
166+
WolframFunction()
167+
except:
168+
print("Wolfram gave up!")
169+
170+
if runCYMATH == True:
171+
try:
172+
CymathFunction()
173+
except:
174+
print("Cymath gave up!")
175+
176+
if runSYMBOLAB == True:
177+
try:
178+
SymbolabFunction()
179+
except:
180+
print("Symbolab gave up!")
181+
'''

0 commit comments

Comments
 (0)