Last active
December 22, 2018 18:53
-
-
Save dojutsu-user/9102fcf9d33f8a13f2266d02066d1c36 to your computer and use it in GitHub Desktop.
This file contains 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
import os | |
import sys | |
import requests | |
from requests.exceptions import ConnectionError | |
from bs4 import BeautifulSoup | |
from utils import get_response | |
HOME_PAGE = 'https://www.google-melange.com' | |
MAIN_PAGE = f'{HOME_PAGE}/archive/gsoc' | |
def get_year_with_link(): | |
"""Get years and their links | |
:returns: A dictionary with years as keys and their links as values | |
:rtype: dict | |
""" | |
response = get_response(MAIN_PAGE) | |
if response.ok: | |
soup = BeautifulSoup(response.text, 'html.parser') | |
years_li = soup.find_all( | |
'li', 'mdl-list__item mdl-list__item--one-line') | |
years_dict = {} | |
for years_html in years_li: | |
year = years_html.text.replace('\n', '') | |
relative_link = years_html.select('a')[0].get('href') | |
full_link = HOME_PAGE + relative_link | |
years_dict[year] = full_link | |
return years_dict | |
else: | |
print('Something Went Wrong') | |
print(f'Status Code: {response.status_code}') | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment