When I use phantomjs to simulate login, there is no problem at all on the local windows, but it does not work when deployed to ubuntu14.04 in the server docker. I find that the page has not been loaded, and I have not found a solution. The simplest example will also fail. For example:
from selenium import webdriver
login_url = "https://www.baidu.com"
img_name = './img.png'
if __name__ == '__main__':
driver = webdriver.PhantomJS()
driver.implicitly_wait(20)
driver.get(login_url)
driver.save_screenshot(img_name)
I have tried implicitly waiting for loading; forced waiting for sleep; adjusting the window size; and the domain names on the page can all be pinged. Nothing is solved. I wonder if something is wrong when installing phantomjs? First, I installed it using apt-get, but --version prompted an error. Then the answer I found according to this error was to download the compressed package from the official website, install it and configure the environment variables. I did the same, and this problem occurred.
Environment:
ubuntu14.04 in docker
python2.7
phantomjs 2.1.1 is installed from the compressed package downloaded from the official website
Screenshot of the last loaded interface:
从截图来看应该是编码的问题,中文字符都无显示
试试
python3
吧,2.7对中文编码一直不太友好 :)1、你可以尝试把获取的源代码保存到文件中,以.html文件保存,用浏览器打开看下页面正常吧。
2、也可能是字符串编码不对,百度一下中文那四个字显示都不正常,你可以在代码中把获取的代码转码一下,然后再处理截图。
可以先试下第一步