-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphd_latest.py
48 lines (44 loc) · 1.02 KB
/
phd_latest.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
import urllib2
from bs4 import BeautifulSoup
import json
class Scraper:
def webscraper(self):
url='http://www.phdcci.in/'
print 'scraping %s '%(url)
arr =[]
dict = {}
dict1={}
soup = BeautifulSoup( urllib2.urlopen(url).read() )
i=soup.find("div",{"class":"newsticker-jcarousellite"})
#print i
#print "love"
for m in i.find_all("li"):
z=m.get_text()
z=' '.join([segment for segment in z.split()])
#dict["news"]=z
dict=return_dict(z)
#print dict1
arr.append(dict)
#print "---------------------------------------------------------------"
#print arr
print arr
return arr
def return_dict(news):
dict={}
dict["news"]=news
try:
print ' %s |||||||||||||||||||||'%(news)
except:
pass
return dict
def main():
scrape = Scraper()
arr1=scrape.webscraper()
#del arr1[-2:]
#del arr1[6]
#print arr1
with open("phd_latest.txt", "w") as f:
f.write(json.dumps(arr1))
if __name__ == '__main__':
main()
#print gen_favicon('flipkart')