Home  >  Q&A  >  body text

python - The page opened using phantomjs is incomplete, what is the problem?

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:

我想大声告诉你我想大声告诉你2690 days ago892

reply all(3)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-18 11:00:18

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

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-18 11:00:18

    Try itpython3, 2.7 has never been very friendly to Chinese encoding :)

    reply
    0
  • 滿天的星座

    滿天的星座2017-05-18 11:00:18

    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

    reply
    0
  • Cancelreply