Last active
June 19, 2016 18:49
-
-
Save sharno/bf93fe297eabb265fc589197720ba855 to your computer and use it in GitHub Desktop.
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
| from selenium import webdriver | |
| import time, json | |
| browser = webdriver.Firefox() | |
| browser.implicitly_wait(10) | |
| browser.get('http://reporterslab.org/fact-checking/') | |
| data = {} | |
| data = {} | |
| browser.find_element_by_class_name('map-toggle').click() | |
| continents = browser.find_elements_by_css_selector('.continent-panel') | |
| for continent in continents: | |
| continent_link = continent.find_element_by_css_selector('.continent-title a') | |
| continent_name = continent_link.text | |
| data[continent_name] = {} | |
| continent_link.click() | |
| countries = continent.find_elements_by_css_selector('.country-list') | |
| for country in countries: | |
| country_name = country.find_element_by_css_selector('.country-title').text | |
| print country_name | |
| data[continent_name][country_name] = {} | |
| orgs = country.find_elements_by_css_selector('li') | |
| for org in orgs: | |
| print org.text | |
| data[continent_name][country_name][org.text] = {} | |
| org.click() | |
| info = browser.find_element_by_css_selector('.info div') | |
| site_name = info.find_element_by_css_selector('.site-name a').text | |
| site_url = info.find_element_by_css_selector('.site-url a').text | |
| info_ps = browser.find_elements_by_css_selector('p') | |
| print [x.text for x in info_ps] | |
| data[continent_name][country_name][org.text] = [x.text for x in info_ps] | |
| print data | |
| f = open("fact.json", "w+") | |
| json.dump(data, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment