我正在MacOS上使用相同的代码进行测试,然后在AWS lambda上进行部署。一切正常,只有一个功能可以获取屏幕截图。
对于AWS Lambda,我正在使用https://github.com/21Buttons/pychromeless
中所述的设置使用
Chrome驱动程序https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zi
def get_image_fullpage_screenshot(browser):
logger.info("get_image_fullpage_screenshot")
required_width = browser.execute_script('return document.body.parentNode.scrollWidth')
required_height = browser.execute_script('return document.body.parentNode.scrollHeight')
browser.set_window_size(required_width, required_height)
logger.info("Browser required_width %d , required_height %d" % (required_width, required_height))
# driver.save_screenshot(path) # has scrollbar
body_element = browser.find_element_by_tag_name('body')
logging.info("Got body")
logging.info(dir(body_element))
bs4 = None
try:
bs4 = body_element.screenshot_as_base64
logging.info("Worked body_element.screenshot")
except Exception as e:
logging.info("Can't body_element.screenshot_as_base64 %s " %str(e))
return bs4
我得到的错误是
Can't body_element.screenshot_as_base64 Message: unknown command: session/1423106400075214591ff2e5def5f55a/element/0.5505971093767275-1/screenshot
但是,对象上的dir是否给出以下信息:
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_execute', '_id', '_parent', '_upload', '_w3c', 'clear', 'click', 'find_element', 'find_element_by_class_name', 'find_element_by_css_selector', 'find_element_by_id', 'find_element_by_link_text', 'find_element_by_name', 'find_element_by_partial_link_text', 'find_element_by_tag_name', 'find_element_by_xpath', 'find_elements', 'find_elements_by_class_name', 'find_elements_by_css_selector', 'find_elements_by_id', 'find_elements_by_link_text', 'find_elements_by_name', 'find_elements_by_partial_link_text', 'find_elements_by_tag_name', 'find_elements_by_xpath', 'get_attribute', 'get_property', 'id', 'is_displayed', 'is_enabled', 'is_selected', 'location', 'location_once_scrolled_into_view', 'parent', 'rect', 'screenshot', 'screenshot_as_base64', 'screenshot_as_png', 'send_keys', 'size', 'submit', 'tag_name', 'text', 'value_of_css_property']
该函数确实存在但不存在?
任何建议都会得到赞赏
答案 0 :(得分:2)
事实证明,lambda内存不足,当然,没有错误。将内存增加到1024MB之后,一切都会按预期进行。
健全性得到恢复。