Web Scraping in Python

def get_data(url, title_selector)
response = requests.get(url)
if status_code == 200
content = str(response.content, ‘utf-8’)
tree = html.fromstring(content)
titles = tree.cssselect(title_selector)
for title in titles:
print(title.text_content())
get_data(
'https://www.python.org',
'div.event-widget > div.shrubbery > ul.menu > li > a'
)
‘div.event-widget > div.shrubbery > ul.menu > li > a’

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store