@@ -0,0 +1,81 @@
3+# @website https://www.bing.com/images
4+# @provide-api yes (http://datamarket.azure.com/dataset/bing/search), max. 5000 query/month
6+# @using-api no (because of query limit)
7+# @results HTML (using search portal)
8+# @stable no (HTML can change)
9+# @parse url, title, img_src
11+# @todo currently there are up to 35 images receive per page, because bing does not parse count=10. limited response to 10 images
13+from urllib import urlencode
14+from cgi import escape
19+# engine dependent config
20+categories = ['images']
24+base_url = 'https://www.bing.com/'
25+search_string = 'images/search?{query}&count=10&first={offset}'
28+def request(query, params):
29+ offset = (params['pageno'] - 1) * 10 + 1
31+ # required for cookie
34+ search_path = search_string.format(
35+ query=urlencode({'q': query}),
38+ params['cookies']['SRCHHPGUSR'] = \
39+ 'NEWWND=0&NRSLT=-1&SRCHLANG=' + language.split('-')[0]
41+ params['url'] = base_url + search_path
48+# get response from search-request
52+ dom = html.fromstring(resp.content)
54+ # init regex for yaml-parsing
55+ p = re.compile( '({|,)([a-z]+):(")')
58+ for result in dom.xpath('//div[@class="dg_u"]'):
59+ link = result.xpath('./a')[0]
61+ # parse yaml-data (it is required to add a space, to make it parsable)
62+ yaml_data = load(p.sub( r'\1\2: \3', link.attrib.get('m')))
64+ title = link.attrib.get('t1')
65+ #url = 'http://' + link.attrib.get('t3')
66+ url = yaml_data.get('surl')
67+ img_src = yaml_data.get('imgurl')
70+ results.append({'template': 'images.html',
76+ # TODO stop parsing if 10 images are found
77+ if len(results) >= 10: