Skip to content

Instantly share code, notes, and snippets.

@nbortolotti
Created January 26, 2016 20:25
Show Gist options
  • Select an option

  • Save nbortolotti/ef1c1da739dc26a3539a to your computer and use it in GitHub Desktop.

Select an option

Save nbortolotti/ef1c1da739dc26a3539a to your computer and use it in GitHub Desktop.
webanalysis scraping
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