w3resource

Python Web Scraping: Get 90 days of visits broken down by browser for all sites on data.gov

Python Web Scraping: Exercise-9 with Solution

Write a Python program to get 90 days of visits broken down by browser for all sites on data.gov.

Sample Solution:

Python Code:

import requests
r = requests.get("https://analytics.usa.gov/data/live/browsers.json")
print("90 days of visits broken down by browser for all sites:")
print(r.json()['totals']['browser'])

Sample Output:

90 days of visits broken down by browser for all sites:
{'Chrome': 1203021255, 'Safari': 741922389, 'Internet Explorer': 309918626, 'Firefox': 131493119, 'Edge': 109923933, 'Samsung Internet': 58972636, 'Android Webview': 25779454, 'Safari (in-app)': 24447414, 'Amazon Silk': 7768291, 'Opera': 7436289, 'Opera Mini': 3754619, 'UC Browser': 1958402, 'Android Browser': 1449470, 'YaBrowser': 578119, 'Mozilla Compatible Agent': 464527, 'Puffin': 293306, 'BlackBerry': 262769, 'Coc Coc': 240167, 'SeaMonkey': 171495, 'Mozilla': 145330, 'Maxthon': 138120, 'StatusCake_Pagespeed_Indev': 23965, 'UCWEB': 72589, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-TOUCHID-6.2.0-Mozilla': 49368, '(not set)': 16340, 'HubSpot inbound link reporting check': 18569, 'Amazon.com': 38496, 'Nintendo Browser': 25373, 'MRCHROME': 22524, 'BestBuy': 19098, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-6.2.0-Mozilla': 9188, 'Carousel': 15920, 'Mercari_d': 7611, 'osee2unifiedRelease': 11019, 'Playstation 3': 12963, 'Nokia Browser': 15251, 'ios-app': 19744, 'HRB-MOBILE-IOS-PHONE-TAXES-TOUCHID-7.7.1-Mozilla': 6964, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-FACEID-6.2.0-Mozilla': 6695, 'ThousandEyes': 10698, 'Iron': 16743, 'Playstation Vita Browser': 8055, 'Google-Test2': 6681, 'YE': 3004, 'Netscape': 5243, 'NetFront': 4118, 'HRB-MOBILE-IOS-PHONE-TAXES-7.7.1-Mozilla': 1306, 'Nintendo 3DS Browser': 3196, 'Seznam': 4069, 'Safari Mozilla': 2099, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-TOUCHID-6.1.1-Mozilla': 741, 'Uzbl': 4682, '--ignore-ssl-errors=true': 25, 'DDG-Android-3.1.1': 2716, 'IE with Chrome Frame': 4676, 'com.seekingalpha.webwrapper': 1638, 'iPhone': 2594, 'Job Search': 318, 'Outlook-iOS': 2323, '+Simple Browser': 1966, 'AdobeAIR': 2437, 'HRB-MOBILE-IOS-PHONE-TAXES-FACEID-7.7.1-Mozilla': 841, 'DDG-Android-3.1.0': 1142, 'Grailed': 978, 'HRB-MOBILE-IOS-TABLET-TAXES-7.7.1-Mozilla': 426, 'HRB-MOBILE-IOS-TABLET-MYBLOCK-TOUCHID-6.2.0-Mozilla': 390, 'HRB-MOBILE-IOS-TABLET-TAXES-TOUCHID-7.7.1-Mozilla': 391, 'Lunascape': 1649, 'HRB-MOBILE-IOS-PHONE-TAXES-TOUCHID-7.7.0-Mozilla': 54, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-TOUCHID-6.1.0-Mozilla': 193, 'LG-B470': 1073, 'Camino': 313, 'Android Runtime': 2445, 'Phantom.js bot': 14, 'Caremark iPhone': 285, 'Sephora 18.2': 1489, 'Mobile IOS 8.5.1.1; Mozilla': 395, 'cwk=1_Mozilla': 15, 'no-ua': 14, 'ScooperBot': 354, 'HRB-MOBILE-IOS-TABLET-MYBLOCK-6.2.0-Mozilla': 73, 'Snowball iPhone 2.0.0': 39, 'DDG-Android-3.0.14': 51, 'FAZDERTAG FAZNETAPPS': 80, 'LiveSlides': 623, 'Android ExpediaBookings': 124, 'Emb': 981, 'One Drop Web Agent': 48, 'Alcatel_A205G-B': 23, 'Nichrome': 92, 'OPS_WATCHER': 446, 'Optional': 294, 'Ratatata': 431, 'iPad': 57, 'Browser': 107, 'Snowball iPhone 2.1.0': 255, 'https:': 12, 'android::org.btelman.stormspotterhelper': 39, '1207 Android mobile': 15, 'Snowball': 104, 'SalesforceMobileSDK': 11, 'windows-phone10-test': 11, 'Empty': 26, 'ThumbSniper': 11, 'BrowserNG': 718, 'Sephora 18.3': 24, 'Mobile IOS 8.5.0.2; Mozilla': 23, 'Windows': 23, 'AncestryAndroid': 75, 'RockMelt': 33, 'tablet': 13, 'pa11y': 777, 'Bluebeam Revu Browser - cef version: 57.0.0.0': 496, 'None': 13, 'Snowball iPhone 2.2.0': 81, 'Sephora 18.3.2': 726, 'NokiaC7-00': 49, 'SpeedaNewsPicks': 120, 'Instagram 44.0.0.9.93 Android': 25, '.': 15, 'android.webview': 32, 'liip': 124, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-TOUCHID-6.3.0-Mozilla': 548, 'Automation_Chrome_54.0.2840.59': 44, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-6.3.0-Mozilla': 95, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-FACEID-6.3.0-Mozilla': 92, 'RTLNieuws': 23, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-TOUCHID-6.4.0-Mozilla': 4902, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-6.4.0-Mozilla': 993, 'HRB-MOBILE-IOS-PHONE-MYBLOCK-FACEID-6.4.0-Mozilla': 733, 'Android': 105, 'something': 13, 'HackeroneBot 1.0': 346, 'Airbnb': 38, 'Snowball iPhone 2.3.1': 119, '"Mozilla': 581, 'Konqueror': 38, 'Sephora 18.4.1': 713, 'InteriaFakty': 109, 'stash-invest-android': 195, 'S40 Ovi Browser': 13, 'RpZd': 16, 'rauS': 16, 'vaxi': 16, '27qF': 15, 'A9CX': 15, 'Gsdg': 15, 'aKga': 15, 'iGdt': 15, 'kLfh': 15, 's2S4': 15, 'vEKQ': 15, 'zEds': 15, 'FqHC': 14, 'Y44w': 14, 'FHLx': 13, 'aPNw': 13, 'rZtr': 13, 'AnXM': 12, 'Snowball iPhone 2.4.1': 47, 'mcpm': 12, 'qd26': 12, 'KDZs': 13, 'bEYM': 13, '9tSG': 11, 'CBC': 23, 'DirectorInsight Autosourcing www.directorinsight.com': 260, 'whater_useragent': 11, 'iGotcha': 24, 'Snowball iPhone 2.5.0': 31, 'User-Agent:Mozilla': 267, 'iCab': 17, 'CareDroidMedications': 21}
 

Flowchart:

Python Web Scraping Flowchart: Get 90 days of visits broken down by browser for all sites on data.gov

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to extract and display all the image links from en.wikipedia.org/wiki/Peter_Jeffrey_(RAAF_officer)
Next: Write a Python program to that retrieves an arbitary Wikipedia page of "Python" and creates a list of links on that page.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/python-exercises/web-scraping/web-scraping-exercise-9.php