Last active
September 3, 2016 05:28
-
-
Save fernandojunior/07be7370cb8fab4eff523b29a1863ad9 to your computer and use it in GitHub Desktop.
selenium python phantomjs test script BeautifulSoup
This file contains hidden or 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
# $ npm -g install phantomjs | |
# $ pip install selenium beautifulsoup4 | |
# $ python | |
>>> from selenium import webdriver | |
>>> PATH = 'node_modules/phantomjs/lib/phantom/bin/phantomjs' | |
>>> browser = webdriver.PhantomJS(executable_path=PATH) | |
>>> # browser = webdriver.Chrome() | |
>>> browser.get('http://foo.bar') | |
>>> browser.execute_script("return ga.create().b.data.values[':trackingId']") | |
UA-64573082-1 | |
>>> from bs4 import BeautifulSoup | |
>>> soup = BeautifulSoup(browser.page_source, 'html.parser') | |
# http://stackoverflow.com/questions/7794087/running-javascript-in-selenium-using-python | |
# http://stackoverflow.com/questions/5585343/getting-the-return-value-of-javascript-code-in-selenium/5585345#5585345 | |
# http://techstonia.com/scraping-with-phantomjs-and-python.html | |
# http://selenium-python.readthedocs.io/installation.html | |
# http://stackoverflow.com/questions/26102132/access-window-object-browser-scope-from-protractor | |
# http://stackoverflow.com/questions/21777306/python-browser-emulator-with-js-support | |
# http://stackoverflow.com/questions/13287490/is-there-a-way-to-use-phantomjs-in-python |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment