en/ProgrammingRobotsCourse/GettingWwwInfo: news.py

File news.py, 458 bytes (added by Ales Horak, 3 years ago)
Line 
1#!/usr/bin/python3
2# -*- coding: utf-8 -*-
3try:
4    from BeautifulSoup import BeautifulSoup
5except:
6    from bs4 import BeautifulSoup
7
8import requests
9
10def main():
11    url = 'https://ihned.cz'
12    page = requests.get(url).text
13    results = []
14    soup = BeautifulSoup(page, features="lxml")
15    results = soup.findAll('h3', attrs={'class':'article-title'})
16    for result in results[0:10]:
17        print(result.text)
18
19if __name__ == "__main__":
20    main()
21