python - The page opened using phantomjs is incomplete, what is the problem?
我想大声告诉你
我想大声告诉你 2017-05-18 10:58:18
0
3
933

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:

我想大声告诉你
我想大声告诉你

reply all(3)
phpcn_u1582

Judging from the screenshots, it seems to be an encoding problem, as no Chinese characters are displayed

漂亮男人

Try itpython3, 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template