Created
January 26, 2016 20:25
-
-
Save nbortolotti/ef1c1da739dc26a3539a to your computer and use it in GitHub Desktop.
webanalysis scraping
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
| def webanalysis(file): | |
| filename =str(datetime.datetime.now()) + '.csv' | |
| myfile = open(filename, 'wb') | |
| try: | |
| writer = csv.writer(myfile) | |
| writer.writerow(('url', 'webcomponents')) | |
| driver = webdriver.PhantomJS( | |
| executable_path='') | |
| driver.implicitly_wait(10) | |
| with open(file) as f: | |
| for url in f: | |
| driver.implicitly_wait(10) | |
| driver.get(url) | |
| scripts = driver.find_elements_by_tag_name("script") | |
| wc = False | |
| for s in scripts: | |
| if "webcomponents" in str(s.get_attribute("src")): | |
| wc = True | |
| break | |
| else: | |
| wc = False | |
| continue | |
| writer.writerow((url, str(wc))) | |
| return filename | |
| finally: | |
| driver.quit() | |
| myfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment