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:
Judging from the screenshots, it seems to be an encoding problem, as no Chinese characters are displayed
Try it
python3
, 2.7 has never been very friendly to Chinese encoding :)1. You can try to save the obtained source code to a file, save it as an .html file, and open it with a browser to see if the page is normal.
2. It may be that the string encoding is incorrect. The four Chinese characters displayed on Baidu are not displayed properly. You can transcode the obtained code in the code and then process the screenshot.
You can try the first step first