|
@@ -1,6 +1,6 @@
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -14,6 +14,7 @@ from urlparse import urljoin
|
|
from urllib import urlencode
|
|
from urllib import urlencode
|
|
from lxml import html
|
|
from lxml import html
|
|
from cgi import escape
|
|
from cgi import escape
|
|
|
|
+from datetime import datetime
|
|
|
|
|
|
|
|
|
|
categories = ['social media']
|
|
categories = ['social media']
|
|
@@ -28,6 +29,7 @@ results_xpath = '//li[@data-item-type="tweet"]'
|
|
link_xpath = './/small[@class="time"]//a'
|
|
link_xpath = './/small[@class="time"]//a'
|
|
title_xpath = './/span[@class="username js-action-profile-name"]//text()'
|
|
title_xpath = './/span[@class="username js-action-profile-name"]//text()'
|
|
content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
|
|
content_xpath = './/p[@class="js-tweet-text tweet-text"]//text()'
|
|
|
|
+timestamp_xpath = './/span[contains(@class,"_timestamp")]'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -53,11 +55,19 @@ def response(resp):
|
|
url = urljoin(base_url, link.attrib.get('href'))
|
|
url = urljoin(base_url, link.attrib.get('href'))
|
|
title = ''.join(tweet.xpath(title_xpath))
|
|
title = ''.join(tweet.xpath(title_xpath))
|
|
content = escape(''.join(tweet.xpath(content_xpath)))
|
|
content = escape(''.join(tweet.xpath(content_xpath)))
|
|
-
|
|
+ pubdate = tweet.xpath(timestamp_xpath)
|
|
-
|
|
+ if len(pubdate) > 0:
|
|
- results.append({'url': url,
|
|
+ publishedDate = datetime.fromtimestamp(float(pubdate[0].attrib.get('data-time')), None)
|
|
- 'title': title,
|
|
+
|
|
- 'content': content})
|
|
+ results.append({'url': url,
|
|
|
|
+ 'title': title,
|
|
|
|
+ 'content': content,
|
|
|
|
+ 'publishedDate': publishedDate})
|
|
|
|
+ else:
|
|
|
|
+
|
|
|
|
+ results.append({'url': url,
|
|
|
|
+ 'title': title,
|
|
|
|
+ 'content': content})
|
|
|
|
|
|
|
|
|
|
return results
|
|
return results
|