Socialabel

Tuesday, October 22, 2013

Parsing hasil query Search Engine Yahoo

Parsing hasil query Search Engine Yahoo

 import urllib2  
 import re  
 from BeautifulSoup import BeautifulSoup  

 opener = urllib2.build_opener()  
 opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0')]  

 query="menjadi pribadi yang terbaik"  
 query=query.replace(' ','+')  
 #url = "http://www.google.com/search?q="  # ok bisa  
 #url = "http://www.bing.com/search?q="    # ok bisa  
 #url = "http://www.ask.com/web?q="        # ok bisa  
 url = "http://search.yahoo.com/search?p=" # ok bisa  
 urlfull=url+query  

 page = opener.open(urlfull)  
 soup = BeautifulSoup(page)  

 ###yahoo, Only  
 for tag in soup.findAll('a', id=True):  
     haha= tag.get('href')  
     ok=haha.split('**')  
     if len(ok)>1:  
       print ok[1].replace("%3a",":")  
Keyword: parsing, yahoo, query, search engine, python

No comments:

Post a Comment