admin管理员组文章数量:1398802
I want to export to png files some web elements from a specific site with webshot R
library.
First, installing and loading libraries:
install.packages("webshot",dependencies = TRUE)
library(webshot)
webshot::install_phantomjs()
I'm testing webshot()
with www.google.es URL. It works well:
webshot("/","google.png", selector="#hplogo")
But If I want to export to PNG image the search engine element:
I write the following code:
webshot("/","google.png", selector=".tsf-p")
What is wrong?
> webshot("/","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("/", "google.png", selector = ".tsf-p") :
webshot.js returned failure value: 1
In addition: Warning message:
running mand '"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\":\"/\",\"file\":\"google.png\",\"vwidth\":992,\"vheight\":744,\"selector\":\".tsf-p\",\"delay\":0.2,\"zoom\":1}]"' had status 1
I want to export to png files some web elements from a specific site with webshot R
library.
First, installing and loading libraries:
install.packages("webshot",dependencies = TRUE)
library(webshot)
webshot::install_phantomjs()
I'm testing webshot()
with www.google.es URL. It works well:
webshot("https://www.google.es/","google.png", selector="#hplogo")
But If I want to export to PNG image the search engine element:
I write the following code:
webshot("https://www.google.es/","google.png", selector=".tsf-p")
What is wrong?
> 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 mand '"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
Share
Improve this question
edited May 16, 2017 at 16:06
Mario M.
asked May 16, 2017 at 15:54
Mario M.Mario M.
8721 gold badge11 silver badges26 bronze badges
2 Answers
Reset to default 1It is possible that there is a web page that opens before (a page to accept cookies). It is therefore necessary to simulate a click to accept cookies.
Then the class seems to have changed:div.o3j99.ikrT4e.om7nvf
Here is a code that works for me :
webshot("https://www.google./", 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 allow to choice rectangle for the shot
I would first try to update the webshot
package. That fixed it for me.
本文标签: javascriptWebshot with R webshotjs returned failure value 1Stack Overflow
版权声明:本文标题:javascript - Webshot with R: webshot.js returned failure value 1 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744122329a2591798.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论