-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghostcontent.py
48 lines (41 loc) · 1.3 KB
/
ghostcontent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Created on Feb 7, 2017
@author: ruixj
'''
from ghost import Ghost
from content import ContentProvider
from content import UrlContentProvider
from commonlog import *
class DynamicContentProvider(ContentProvider):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.gh = None
self.page = None
self.staticPageContent = UrlContentProvider()
def getContent(self,url):
if( self.gh is None):
self.gh = Ghost()
self.page, self.page_name = self.gh.create_page(600)
try:
self.page_resource = self.page.open(url, wait_onload_event=True)
except Exception,e:
LelianLogger.log('main',logging.ERROR,u"Timeout to get page: %s",url)
self.content = self.staticPageContent.getContent(url)
return self.content
return self.page.content
if __name__ == '__main__':
url = 'https://36kr.com/p/5061197.html'
gh = Ghost()
# We create a new page
page, page_name = gh.create_page()
# We load the main page of ebay
page_resource = page.open(url, wait_onload_event=True)
print page.content
url = 'http://www.baidu.com'
page_resource = page.open(url, wait_onload_event=True)
print page.content