on master help sign in
[fix] yahoo url extraction
commit0fc481f47ed8116b3acd4dd11c0527994582d526 authorAdam Tauber <asciimoo@gmail.com> dateSat 8 Mar 2014, 19:09 (13 years ago) parentaa9df5b
2 files changed+7−9
searx/engines/yahoo.py+5−4 searx/engines/yahoo_news.py+2−5
searx/engines/yahoo.py+5−4
@@ -15,6 +15,10 @@ suggestion_xpath = '//div[@id="satat"]//a'
1515
1616paging = True
1717
18+def parse_url(url_string):
19+ start = url_string.find('http', url_string.find('/RU=')+1)
20+ end = min(url_string.rfind('/RS'), url_string.rfind('/RK'))
21+ return unquote(url_string[start:end])
1822
1923def request(query, params):
2024 offset = (params['pageno'] - 1) * 10 + 1
@@ -34,10 +38,7 @@ def response(resp):
3438 dom = html.fromstring(resp.text)
3539
3640 for result in dom.xpath(results_xpath):
37− url_string = extract_url(result.xpath(url_xpath), search_url)
38− start = url_string.find('http', url_string.find('/RU=')+1)
39− end = url_string.rfind('/RS')
40− url = unquote(url_string[start:end])
41+ url = parse_url(extract_url(result.xpath(url_xpath), search_url))
4142 title = extract_text(result.xpath(title_xpath)[0])
4243 content = extract_text(result.xpath(content_xpath)[0])
4344 results.append({'url': url, 'title': title, 'content': content})
searx/engines/yahoo_news.py+2−5
@@ -1,9 +1,9 @@
11#!/usr/bin/env python
22
33from urllib import urlencode
4−from urlparse import unquote
54from lxml import html
65from searx.engines.xpath import extract_text, extract_url
6+from searx.engines.yahoo import parse_url
77
88categories = ['news']
99search_url = 'http://news.search.yahoo.com/search?{query}&b={offset}'
@@ -34,10 +34,7 @@ def response(resp):
3434 dom = html.fromstring(resp.text)
3535
3636 for result in dom.xpath(results_xpath):
37− url_string = extract_url(result.xpath(url_xpath), search_url)
38− start = url_string.find('http', url_string.find('/RU=')+1)
39− end = url_string.rfind('/RS')
40− url = unquote(url_string[start:end])
37+ url = parse_url(extract_url(result.xpath(url_xpath), search_url))
4138 title = extract_text(result.xpath(title_xpath)[0])
4239 content = extract_text(result.xpath(content_xpath)[0])
4340 results.append({'url': url, 'title': title, 'content': content})