感谢 PhantomJS,我正在尝试抓取此网页:https : //www.koshkamashkaeshop.com/fr/28-robes-Koshka-Mashka 但每次都无法加载。我认为这是因为https。这是我的 .sh 代码:
phantomjs --ignore-ssl-errors=yes test.js
Run Code Online (Sandbox Code Playgroud)
这是我的 test.js 代码:
page.open(url, function (status) {
var content = page.evaluate(function()
{
if (status !== 'success') {
console.log('FAIL to load the address');
}else{
}
}
)})
Run Code Online (Sandbox Code Playgroud) 我已经搜索了很长时间,但我找不到如何使用 selenium 和 python 禁用 phantomjs 的 cookie。我无法理解 phantomjs 的文档。请有人帮助我。
我的问题与在Windows 7/OSX上无法安装jasmine-core略有不同
我试过这个命令:
npm install karma karma-jasmine karma-phantomjs-launcher --save-dev
Run Code Online (Sandbox Code Playgroud)
我在答案中看到Karma不支持Node的v.5.3.0(它似乎与我的v.5.2.0版本相同).
但是我能做什么?引用的线程没有给出解决问题的任何答案...降级节点和我安装的每个包?如何?这管用吗?我是这些技术的新手.
以下是我得到的错误:
??? UNMET PEER DEPENDENCY jasmine-core@*
??? UNMET PEER DEPENDENCY phantomjs@>=1.9
npm WARN karma-jasmine@0.3.6 requires a peer of jasmine-core@* but none was installed.
npm WARN karma-phantomjs-launcher@0.2.2 requires a peer of phantomjs@>=1.9 but none was installed.
Run Code Online (Sandbox Code Playgroud)
另一个问题是
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: fsevents@1.0.6
Run Code Online (Sandbox Code Playgroud)
那我该怎么办?
我想将数据从casper JS传递到我目前使用的CSV文件
fs = require('fs');
fs.write('test.csv', "name, title", "a");
fs.write('test.csv', name.trim()+","+title.trim(), "a");
Run Code Online (Sandbox Code Playgroud)
这是一个循环,所以有很多记录
但是打印到CSV文件不会插入新行.它目前写得像这样,我只想要2列
Name Title
name1 name1 name2 title2 name3 title3
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Maven 和 Java 项目中使用 Selenium 和 PhantomJS。
以下是我在 pom.xml 文件中使用的依赖项:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>2.53.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>1.4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jenkins-releases</id>
<url>http://repo.jenkins-ci.org/releases/</url>
</repository>
</repositories>`
Run Code Online (Sandbox Code Playgroud)
在我的 Java 文件中,我尝试使用以下方法设置 PhantomJS 驱动程序,而我的计算机上没有 JAR 文件:
public void set_up(){
PhantomJsDriverManager.getInstance().setup();
// Configuration du driver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
driver = new PhantomJSDriver(capabilities);
}
Run Code Online (Sandbox Code Playgroud)
当我第一次尝试这个时,它运行良好,但一两个星期后,我收到了这个错误:
public void set_up(){
PhantomJsDriverManager.getInstance().setup();
// Configuration du driver
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
driver = …
Run Code Online (Sandbox Code Playgroud) 我运行一个使用 selenium 和 phantomjs 的 python 程序并得到这些错误 2) 和 3) 然后当我运行 pip install selenium 时我得到错误 1):
1) 当前未安装程序“pip”。
2)导入错误:没有名为“硒”的模块
3) selenium.common.exceptions.WebDriverException: 消息:'phantomjs' 可执行文件需要在 PATH 中。
全部在 Ubuntu 14.04 x64 上完成
有没有办法使用Geb获取原始页面内容?
例如,下面的测试应该可以工作(但是PhantomJS似乎很糟糕,使用HTML代码的JSON响应):
def "Get page content example -- health check"() {
given:
go "https://status.github.com/api/status.json"
expect:
assert driver.pageSource.startsWith('{"status":"(good)"')
}
Run Code Online (Sandbox Code Playgroud)
请注意,是的,我明白我可以不使用Geb,只是在Groovy中进行URL调用,但由于多种原因我想明确使用Geb(其中一个原因是处理重定向).
你如何在Geb中设置cookie?我遇到了给定示例的以下错误:
org.openqa.selenium.InvalidCookieDomainException:{"errorMessage":"只能为当前域设置Cookie"....
..我也尝试使用Cookie生成器显式设置cookie多米诺骨牌虽然这只会导致另一个异常:org.openqa.selenium.UnableToSetCookieException:{"errorMessage":"无法设置Cookie"}
请注意,我曾经在GebConfig.groovy文件中有一个baseURL ..但我也删除了它..除了PhantomJS驱动程序配置之外,配置文件中没有设置.
我在OSX上使用PhantomJS最新版本(1.3.0 jar和2.1.1驱动程序OSX).
请注意,示例DOES因某些原因使用Chrome Webdriver.
import geb.spock.GebSpec
import org.openqa.selenium.Cookie
class SetCookieIT extends GebSpec {
def "Cookie example"() {
given:
def options = driver.manage()
when:
go "https://www.wikipedia.org/"
then:
!options.getCookieNamed("my-geb-cookie")
when:
options.addCookie(new Cookie("my-geb-cookie", "foobar"))
go "https://www.wikipedia.org/"
then:
title == "Wikipedia"
options.getCookieNamed("my-geb-cookie").value == "foobar"
}
}
Run Code Online (Sandbox Code Playgroud) 我正在编写CasperJS测试脚本的最后一部分,我需要渲染一个被操作的网页的.png图像并将其保存到我选择的目录中.谁知道我怎么能这样做?
提前致谢
我正在尝试使用Selenium和PhantomJS设置无头测试环境.
我已经创建了一个文件夹c:/phantomjs
并将所有phantomjs脚本文件放在那里(下载后).
然后我创建了一个文件夹 C:\xampp\htdocs\testPhantomJS
现在我在我的系统中安装了nodeJS.
然后我遍历到C:\xampp\htdocs\testPhantomJS
命令提示符并安装了phantomJS,如下所示:
C:\xampp\htdocs\testPhantomJS>npm install -g phantomjs
图像表示不同的位置.那是因为它来自我同事的电脑.我们都在进行同样的安装,他把图像发给我参考.这就是为什么它与我的文件夹位置不同,但我说的位置,它是我工作的那个.
现在在命令提示符下键入phantomjs,当我们输入时
C:\xampp\htdocs\testPhantomJS>phantomjs
phantom>
我C:\xampp\htdocs\testPhantomJS
在命令提示符中遍历并安装了selenium webdriver,如下所示:
C:\xampp\htdocs\testPhantomJS>npm install selenium-webdriver
现在我有一个测试脚本test.js
,如下所示:
describe('Test example.com', function(){
before(function(done) {
client.init().url('http://google.com', done);
});
describe('Check homepage', function(){
it('should see the correct title', function(done) {
client.getTitle(function(err, title){
expect(title).to.have.string('Example Domain');
done();
});
});
it('should see the body', function(done) {
client.getText('p', function(err, p){
expect(p).to.have.string(
'for illustrative examples in documents.'
);
done();
})
});
});
after(function(done) {
client.end();
done(); …
Run Code Online (Sandbox Code Playgroud)