w3resource

Python Web Scraping: Get the number of datasets currently listed on data.gov

Python Web Scraping: Exercise-3 with Solution

Write a Python program to get the number of datasets currently listed on data.gov.

Sample Solution:

Python Code:

from lxml import html
import requests
response = requests.get('http://www.data.gov/')
doc_gov = html.fromstring(response.text)
link_gov = doc_gov.cssselect('small a')[0]
print("Number of datasets currently listed on data.gov:")
print(link_gov.text)

Sample Output:

Number of datasets currently listed on data.gov:
285,397 datasets
 

Flowchart:

Python Web Scraping Flowchart: Get the number of datasets currently listed 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 download and display the content of robot.txt for en.wikipedia.org.
Next: Write a Python program to convert an address into geographic coordinates.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.