-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
48 lines (39 loc) · 1.11 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env/python
# -*- coding: utf-8 -*-
#''''
#CLient web per www.udl.cat
#@author:jpcg
#''''
import urllib2
from bs4 import BeautifulSoup
#classe que deriva de object
class Client(object):
def get_web(self,page):
"""baixar-se la web"""
f=urllib2.urlopen(page)
html=f.read()
f.close()
return html
#TODO:buscar el text
def search_text(self,html):
soup = BeautifulSoup(html, 'html.parser')
elements=soup.find_all("div","featured-links-item")
resultats=[]
for element in elements:
data=element.find("time")["datetime"]
title=element.find("span", "flink-title")
if title:
title=title.text
else:
title="Sense Titol"
resultats.append((data,title))
return resultats
def main(self):
web = self.get_web("http://www.udl.cat/")
resultat=self.search_text(web)
#FIXME:imprimir els resultats
print (resultat)
if __name__ == "__main__":#name variable interna
client = Client()
client.main()
pass