Python Web Scraping: Get the number of Pinterest accounts maintained by US state department embassies and missions
Python Web Scraping: Exercise-15 with Solution
Write a Python program to get the number of Pinterest accounts maintained by U.S. State Department embassies and missions.
#https://bit.ly/2lVhlLX import requests from lxml import html url = 'http://www.state.gov/r/pa/ode/socialmedia/' doc = html.fromstring(requests.get(url).text) pinlinks = [a for a in doc.cssselect('a') if 'pinterest.com' in str(a.attrib.get('href'))] print("The number of Pinterest accounts maintained by U.S. State Department embassies and missions:") print(len(pinlinks))
The number of Pinterest accounts maintained by U.S. State Department embassies and missions: 3
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework