def get(self, url, xpath, timeout, retry, service_args, desired_capabilities):
browser = None
try:
result = dict()
if desired_capabilities:
DesiredCapabilities.PHANTOMJS.update(json.loads(desired_capabilities))
browser = webdriver.PhantomJS(service_args=json.loads(service_args) if service_args else None,
desired_capabilities=DesiredCapabilities.PHANTOMJS)
count = 0
while (retry + 1) > count:
count += 1
try:
browser.get(url)
break
except Exception as e:
print str(e)
if xpath:
browser.implicitly_wait(timeout)
try:
browser.find_element_by_xpath(xpath)
except Exception as e:
print str(e)
text = browser.page_source
if text == '<html><head></head><body></body></html>':
browser.quit()
return ''
result['cookies'] = browser.get_cookies()
result['text'] = text.encode('utf-8')
browser.quit()
return json.dumps(result)
except Exception as e:
if browser:
browser.quit()
print str(e)
return ''
评论列表
文章目录