phantomjs 不加载 instagram 和 pintersest 网页
phantomjs not loading instagram and pintersest webpages
我在 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>
但它仍然是空的。
Instagram 页面在 Mac OS X 10.11.6 下的 python 2.7.10 中正确加载了 PhantomJS 2.1.1; Ubuntu 服务器下的 PhantomJS 可以正确加载许多其他网站(twitter、tumblr 等),所以我猜 Ubuntu 服务器中缺少一些模块但无法理解是哪个。
它既无法加载 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
它没有正确加载页面(即使它有所有第三方原子)。
有没有办法使用apt-get安装的可执行文件和npm安装的第三方Atoms?
已解决。
我解决了直接从 git 存储库在 Ubuntu 服务器上编译 phantomjs 的问题。
所以也许预编译的二进制文件不完整。
我在 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>
但它仍然是空的。
Instagram 页面在 Mac OS X 10.11.6 下的 python 2.7.10 中正确加载了 PhantomJS 2.1.1; Ubuntu 服务器下的 PhantomJS 可以正确加载许多其他网站(twitter、tumblr 等),所以我猜 Ubuntu 服务器中缺少一些模块但无法理解是哪个。
它既无法加载 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
更新: 使用
安装 phantomjssudo apt-get install phantomjs
它正确加载了整个页面。但是这个包缺少一些重要的第三方依赖项(例如find_element Atom)。
安装 phantomjs
npm install phantomjs-prebuilt
它没有正确加载页面(即使它有所有第三方原子)。
有没有办法使用apt-get安装的可执行文件和npm安装的第三方Atoms?
已解决。
我解决了直接从 git 存储库在 Ubuntu 服务器上编译 phantomjs 的问题。 所以也许预编译的二进制文件不完整。