Phantomjs不加载instagram和pinterest网页

phantomjs not loading instagram and pintersest webpages

本文关键字:pinterest 网页 instagram 加载 Phantomjs      更新时间:2023-09-26

我在Ubuntu Server 16.04.1下使用python 2.7.12中的PhantomJS 2.1.1,显示来自pyvirtualdisplay

PhantomJS无法加载instagram交互式dom页面(https://www.instagram.com/accounts/login/)。页面代码应该在

<span id="react-root"></span>

,但仍为空

在Mac OS X 10.11.6下,使用python 2.7.10中的PhantomJS 2.1.1正确加载Instagram页面;在Ubuntu Server下的PhantomJS可以正确加载许多其他网站(twitter, tumblr等),所以我猜在Ubuntu Server中有一些缺失的模块,但无法理解是哪一个。

它既不能加载https://www.pinterest.com/login/,但使用curl可以正确加载此页面。

有人能帮忙吗?谢谢你。

下面是python代码:

from selenium import webdriver
from pytvirtualdisplay import Display
display = Display(visible=0,size=(800,600))
display.start()
browser = webdriver.PhantomJS()
browser.set_window_size(800, 600)
browser.get('https://www.instagram.com/accounts/login/')

browser.get('https://www.pinterest.com/login/')

ghostdriver.log

[INFO  - 2016-09-12T16:08:37.057Z] GhostDriver - Main - running on port 49739
[INFO  - 2016-09-12T16:08:37.933Z] Session [2a14fc60-7903-11e6-a755-53e4799f55f3] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2016-09-12T16:08:37.933Z] Session [2a14fc60-7903-11e6-a755-53e4799f55f3] - page.customHeaders:  - {}
[INFO  - 2016-09-12T16:08:37.933Z] Session [2a14fc60-7903-11e6-a755-53e4799f55f3] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2016-09-12T16:08:37.934Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 2a14fc60-7903-11e6-a755-53e4799f55f3

更新:使用

安装phantomjs
sudo apt-get install phantomjs

可以正确加载整个页面。但是这个包缺少一些重要的第三方依赖项(比如find_element Atom)。

使用

安装phantomjs
npm install phantomjs-prebuilt

它不能正确加载页面(即使它已经获得了所有第三方atom)。

是否有办法使用apt-get和npm安装的第三方原子安装的可执行文件?

SOLVED.

我解决了在Ubuntu服务器上直接从git库编译phantomjs。因此,预编译的二进制文件可能不完整。

详情在此:http://phantomjs.org/build.html