67def response(resp):
68 results = []
69 dom = html.fromstring(resp.text)
70
71
72 for result in eval_xpath_list(dom, '//ol[contains(@class,"searchCenterMiddle")]//li'):
73
74 url = eval_xpath_getindex(result, './/h4/a/@href', 0, None)
75 if url is None:
76 continue
77 url = parse_url(url)
78 title = extract_text(result.xpath('.//h4/a'))
79 content = extract_text(result.xpath('.//p'))
80 thumbnail = eval_xpath_getindex(result, './/img/@data-src', 0, None)
81
82 item = {'url': url, 'title': title, 'content': content, 'thumbnail': thumbnail}
83
84 pub_date = extract_text(result.xpath('.//span[contains(@class,"s-time")]'))
85 ago = AGO_RE.search(pub_date)
86 if ago:
87 number = int(ago.group(1))
88 delta = AGO_TIMEDELTA[ago.group(2)]
89 pub_date = datetime.now() - delta * number
90 else:
91 try:
92 pub_date = parser.parse(pub_date)
93 except parser.ParserError:
94 pub_date = None
95
96 if pub_date is not None:
97 item['publishedDate'] = pub_date
98 results.append(item)
99
100 for suggestion in eval_xpath_list(dom, '//div[contains(@class,"AlsoTry")]//td'):
101 results.append({'suggestion': extract_text(suggestion)})
102
103 return results