Last active
December 10, 2016 19:34
-
-
Save shlaikov/5d175630bab4502b4f2cdbd997558f4a to your computer and use it in GitHub Desktop.
Parsing python.org site.
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
from bs4 import BeautifulSoup | |
import urllib.request as url | |
def parse(): | |
page = url.urlopen('http://python.org').read() | |
soup = BeautifulSoup(page, 'html.parser') | |
soup.prettify() | |
main_div = soup.find('div', class_="medium-widget event-widget last",) | |
ul_tag = main_div.find('ul', class_="menu") | |
times, events = [], [] | |
for time_tag in ul_tag.find_all('time'): | |
times.append(str(time_tag.text)) | |
for event_tag in ul_tag.find_all('a'): | |
events.append(str(event_tag.text)) | |
print("====================================") | |
for time, event in zip(times, events): | |
print(time + " " + event) | |
print("====================================") | |
def main(): | |
parse() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment