【问题标题】:Webshot with R: webshot.js returned failure value 1带有 R 的 Webshot:webshot.js 返回失败值 1
【发布时间】:2017-10-15 19:32:36
【问题描述】:

我想使用 webshot R 库从特定站点将一些 Web 元素导出到 png 文件。

首先,安装和加载库:

install.packages("webshot",dependencies = TRUE)
library(webshot)
webshot::install_phantomjs()

我正在使用 www.google.es 网址测试 webshot()。效果很好:

webshot("https://www.google.es/","google.png", selector="#hplogo")

但如果我想将搜索引擎元素导出为 PNG 图像:

我写了以下代码:

webshot("https://www.google.es/","google.png", selector=".tsf-p")

怎么了?

> webshot("https://www.google.es/","google.png", selector=".tsf-p")
PHANTOM ERROR: CasperError: No element matching selector found: .tsf-p
TRACE:
 -> phantomjs://platform/casper.js: 1066 (in function getElementBounds)
 -> phantomjs://code/webshot.js: 137
 -> undefined: 0 (in function map)
 -> phantomjs://code/webshot.js: 136 (in function findClipRect)
 -> phantomjs://code/webshot.js: 85
 -> phantomjs://platform/casper.js: 2188 (in function _check)
Error in webshot("https://www.google.es/", "google.png", selector = ".tsf-p") : 
  webshot.js returned failure value: 1
In addition: Warning message:
running command '"C:\Users\Mario Martínez\AppData\Roaming/PhantomJS/phantomjs.exe" "C:/Users/Mario Martínez/Documents/R/win-library/3.3/webshot/webshot.js" "[{\"url\":\"https://www.google.es/\",\"file\":\"google.png\",\"vwidth\":992,\"vheight\":744,\"selector\":\".tsf-p\",\"delay\":0.2,\"zoom\":1}]"' had status 1 

【问题讨论】:

    标签: javascript jquery html r phantomjs


    【解决方案1】:

    有可能之前打开了一个网页(接受 cookie 的页面)。 因此需要模拟点击接受cookies。

    然后类好像变了:div.o3j99.ikrT4e.om7nvf

    这是一个适合我的代码:

        webshot("https://www.google.com/", file = "Test.png", 
        eval = "casper.then(function() {
        this.click('#L2AGLb'); // click cookies accept
        this.sendKeys('input.gLFyf.gsfi', 'test_text_research', {keepFocus: true}); // add text in search bar
        this.wait(1000);
        });",
        cliprect = c(200, 150, 800, 300)) 
    

    cliprect 允许为镜头选择矩形

    【讨论】:

      猜你喜欢
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多