|  | @@ -4,12 +4,15 @@ from cgi import escape
 | 
	
		
			
			| 4 | 4 |  
 | 
	
		
			
			| 5 | 5 |  base_url = 'http://www.bing.com/'
 | 
	
		
			
			| 6 | 6 |  search_string = 'search?{query}'
 | 
	
		
			
			|  | 7 | +language = 'en-us' # see http://msdn.microsoft.com/en-us/library/dd251064.aspx
 | 
	
		
			
			|  | 8 | +
 | 
	
		
			
			| 7 | 9 |  
 | 
	
		
			
			| 8 | 10 |  def request(query, params):
 | 
	
		
			
			| 9 |  | -    search_path = search_string.format(query=urlencode({'q': query}))
 | 
	
		
			
			|  | 11 | +    search_path = search_string.format(query=urlencode({'q': query, 'setmkt': language}))
 | 
	
		
			
			| 10 | 12 |      #if params['category'] == 'images':
 | 
	
		
			
			| 11 | 13 |      #    params['url'] = base_url + 'images/' + search_path
 | 
	
		
			
			| 12 | 14 |      params['url'] = base_url + search_path
 | 
	
		
			
			|  | 15 | +    print params['url']
 | 
	
		
			
			| 13 | 16 |      return params
 | 
	
		
			
			| 14 | 17 |  
 | 
	
		
			
			| 15 | 18 |  
 | 
	
	
		
			
			|  | @@ -23,4 +26,14 @@ def response(resp):
 | 
	
		
			
			| 23 | 26 |          title = ' '.join(link.xpath('.//text()'))
 | 
	
		
			
			| 24 | 27 |          content = escape(' '.join(result.xpath('.//p//text()')))
 | 
	
		
			
			| 25 | 28 |          results.append({'url': url, 'title': title, 'content': content})
 | 
	
		
			
			|  | 29 | +
 | 
	
		
			
			|  | 30 | +    if results:
 | 
	
		
			
			|  | 31 | +        return results
 | 
	
		
			
			|  | 32 | +
 | 
	
		
			
			|  | 33 | +    for result in dom.xpath('//li[@class="b_algo"]'):
 | 
	
		
			
			|  | 34 | +        link = result.xpath('.//h2/a')[0]
 | 
	
		
			
			|  | 35 | +        url = link.attrib.get('href')
 | 
	
		
			
			|  | 36 | +        title = ' '.join(link.xpath('.//text()'))
 | 
	
		
			
			|  | 37 | +        content = escape(' '.join(result.xpath('.//p//text()')))
 | 
	
		
			
			|  | 38 | +        results.append({'url': url, 'title': title, 'content': content})
 | 
	
		
			
			| 26 | 39 |      return results
 |