Skip to content

Commit 6439a9f

Browse files
author
Jesse Osiecki
committed
Remove PhantomJS
1 parent 1ea535a commit 6439a9f

File tree

1 file changed

+21
-75
lines changed

1 file changed

+21
-75
lines changed

httpscreenshot.py

Lines changed: 21 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
#!/usr/bin/python3
2-
"""
3-
Installation on Ubuntu:
4-
apt-get install python-requests python-m2crypto phantomjs
5-
If you run into: 'module' object has no attribute 'PhantomJS'
6-
then pip install selenium (or pip install --upgrade selenium)
7-
"""
82

93
from selenium import webdriver
104
from urllib.parse import urlparse
@@ -185,28 +179,28 @@ def setupBrowserProfile(headless, proxy):
185179

186180
while browser is None:
187181
try:
188-
if not headless:
189-
capabilities = DesiredCapabilities.FIREFOX
190-
capabilities["acceptSslCerts"] = True
191-
fp = webdriver.FirefoxProfile()
192-
fp.set_preference("webdriver.accept.untrusted.certs", True)
193-
fp.set_preference("security.enable_java", False)
194-
fp.set_preference("webdriver.load.strategy", "fast")
195-
if proxy is not None:
196-
proxyItems = proxy.split(":")
197-
fp.set_preference("network.proxy.socks", proxyItems[0])
198-
fp.set_preference("network.proxy.socks_port",
199-
int(proxyItems[1]))
200-
fp.set_preference("network.proxy.type", 1)
201-
browser = webdriver.Firefox(firefox_profile=fp,
202-
capabilities=capabilities)
203-
else:
204-
capabilities = DesiredCapabilities.FIREFOX
205-
capabilities["acceptSslCerts"] = True
206-
fireFoxOptions = webdriver.FirefoxOptions()
182+
capabilities = DesiredCapabilities.FIREFOX
183+
capabilities["acceptSslCerts"] = True
184+
fp = webdriver.FirefoxProfile()
185+
fp.set_preference("webdriver.accept.untrusted.certs", True)
186+
fp.set_preference("security.enable_java", False)
187+
fp.set_preference("webdriver.load.strategy", "fast")
188+
if proxy is not None:
189+
proxyItems = proxy.split(":")
190+
fp.set_preference("network.proxy.socks", proxyItems[0])
191+
fp.set_preference("network.proxy.socks_port",
192+
int(proxyItems[1]))
193+
fp.set_preference("network.proxy.type", 1)
194+
195+
fireFoxOptions = webdriver.FirefoxOptions()
196+
197+
if headless:
207198
fireFoxOptions.set_headless()
208-
browser = webdriver.Firefox(firefox_options=fireFoxOptions, capabilities=capabilities)
209-
browser.set_window_size(1024, 768)
199+
200+
browser = webdriver.Firefox(firefox_profile=fp,
201+
capabilities=capabilities,
202+
options=fireFoxOptions)
203+
browser.set_window_size(1024, 768)
210204

211205
except Exception as e:
212206
print(e)
@@ -339,61 +333,13 @@ def worker(
339333
if smartFetch:
340334
hash_basket[resp_hash] = screenshotName
341335

342-
# browser.set_window_size(1024, 768)
343336
browser.set_page_load_timeout((tout))
344337
old_url = browser.current_url
345338
browser.get(curUrl[0].strip())
346339
if browser.current_url == old_url:
347340
print(
348341
"[-] Error fetching in browser but successfully fetched with Requests: "
349342
+ curUrl[0])
350-
if headless:
351-
browser2 = None
352-
if debug:
353-
print(
354-
"[+] Trying with sslv3 instead of TLS - known phantomjs bug: "
355-
+ curUrl[0])
356-
if proxy is not None:
357-
browser2 = webdriver.PhantomJS(
358-
service_args=[
359-
"--ignore-ssl-errors=true",
360-
"--proxy=" + proxy,
361-
"--proxy-type=socks5",
362-
],
363-
executable_path="phantomjs",
364-
)
365-
else:
366-
browser2 = webdriver.PhantomJS(
367-
service_args=["--ignore-ssl-errors=true"],
368-
executable_path="phantomjs",
369-
)
370-
# print "Launched browser2: "+str(browser2.service.process.pid)
371-
372-
old_url = browser2.current_url
373-
try:
374-
browser2.get(curUrl[0].strip())
375-
if browser2.current_url == old_url:
376-
if debug:
377-
print(
378-
"[-] Didn't work with SSLv3 either..."
379-
+ curUrl[0])
380-
browser2.quit()
381-
else:
382-
print("[+] Saving: " + screenshotName)
383-
html_source = browser2.page_source
384-
f = open(screenshotName + ".html", "w")
385-
f.write(html_source)
386-
f.close()
387-
browser2.save_screenshot(screenshotName +
388-
".png")
389-
browser2.quit()
390-
continue
391-
except:
392-
browser2.quit()
393-
print(
394-
"[-] Didn't work with SSLv3 either - exception..."
395-
+ curUrl[0])
396-
397343
if tryGUIOnFail and headless:
398344
display = Display(visible=0, size=(1024, 768))
399345
display.start()

0 commit comments

Comments
 (0)