1.webelementԴ?源码?
webelementԴ??
如果GET方法可以发送请求,那么HttpConnection是源码可以搞定的,就是源码养猪管理系统 源码拼接下URL字符串而已。如果是源码POST方式发送请求的,而且网站只是源码购物卡原生APP源码一个简单提交表单,那么WebDriver这个开源项目,源码火柴人游戏源码csdn使用这个项目自带的源码浏览器驱动(一个简单的浏览器,不会显示浏览器具体操作,源码但可以模拟相关的源码操作)是可以满足你的要求的。
给你一个简单的源码例子:
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class TestHtmlUnitDriver {
/
*** @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HtmlUnitDriver dr = new HtmlUnitDriver(false); //使用自动的简单HTML浏览器驱动,false为不显示DEBUG信息。源码
dr.get("
);
//检查页面title
System.out.println("页面Title:"+dr.getTitle());
WebElement el = dr.findElement(By.xpath("//html"));
// System.out.println(el.getText());
WebElement input = dr.findElement(By.id("kw"));
//搜索关键字
input.sendKeys("webDriver");
WebElement button = dr.findElement(By.id("su"));
//提交表单 webDriver会自动从表单中查找提交按钮并提交
button.click();
//或者直接
//input.submit();
//检查页面title
System.out.println("页面Title:"+dr.getTitle());
dr.close();
}
}
另外一种方式,源码JDK自带的源码价格计算小程序源码HttpConnection
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class TestHttpURLConnection {
/
*** @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String url="/s?wd=WebDriver&ie=utf-8";
try {
HttpURLConnection httpUrlConnection = (HttpURLConnection) new URL(url).openConnection();
httpUrlConnection.setRequestMethod("GET");
httpUrlConnection.setUseCaches(true); //使用缓存
httpUrlConnection.connect(); //建立连接
InputStream inputStream = httpUrlConnection.getInputStream(); //读取输入流
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String string;
while ((string = bufferedReader.readLine()) != null) {
System.out.println(string); //打印输出
}
bufferedReader.close();
inputStream.close();
httpUrlConnection.disconnect();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //创建连接
}
}