forked from jsanyam/My-Duniya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_tag.py
32 lines (30 loc) · 1.09 KB
/
search_tag.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
def search_to_json(search):
from urllib2 import urlopen
from bs4 import BeautifulSoup
import json
url_base='http://aninews.in/newsdetail/keyword-search/'
search_str=search.replace(' ','-')
url_end='.html'
url= url_base+search_str+url_end
html= urlopen(url)
bsObj=BeautifulSoup(html,"html.parser")
resultset=bsObj.findAll("div",attrs={"class":"catnewsbox"})
list=[]
i=0
for result in resultset:
i=i+1
if(i==7):
break
url=result.find("a")["href"]
html= urlopen(url)
bsObj=BeautifulSoup(html,"html.parser")
image=bsObj.find("meta",attrs={"property":"og:image"})["content"]
title=bsObj.find("meta",attrs={"property":"og:title"})["content"]
story=bsObj.find("span",attrs={"style":"text-align:left;"}).get_text()
description=bsObj.find("meta",attrs={"name":"description"})["content"]
# print title
# print image
# print description
# print story
list.append({"title":title,"image":image,"description":description,"story":story})
return list