我只是想知道是否可以浏览一个网站(无需浏览器UI),然后在文本框中输入文本并按下按钮。是否可以浏览一个网站“没有浏览器”?
是否有任何库可以执行此操作或Java中的任何方法来连接到站点并输入信息并按按钮。
我只是想知道是否可以浏览一个网站(无需浏览器UI),然后在文本框中输入文本并按下按钮。是否可以浏览一个网站“没有浏览器”?
是否有任何库可以执行此操作或Java中的任何方法来连接到站点并输入信息并按按钮。
听起来就像你在找Selenium。
下面是从他们的Getting Started指南谷歌搜索的例子:
package org.openqa.selenium.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class Example {
public static void main(String[] args) {
// Create a new instance of the html unit driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new HtmlUnitDriver();
// And now use this to visit Google
driver.get("http://www.google.com");
// Find the text input element by its name
WebElement element = driver.findElement(By.name("q"));
// Enter something to search for
element.sendKeys("Cheese!");
// Now submit the form. WebDriver will find the form for us from the element
element.submit();
// Check the title of the page
System.out.println("Page title is: " + driver.getTitle());
}
}
如果你想'无头'去找到Selenium的PhantomJS webdriver –
@DavidSarmiento你是什么意思“无头”? – user2612619
没有窗口显示。一个'隐藏'的浏览器实例。 –
是的,这是可能的。搜索“无头浏览器”。 –
[Selenium](http://www.seleniumhq.org/)。 – Kapep