更换显示器桌面横正常后,只显示桌面背景图片,换回来后一切正常

用Watij爬取网页内容 - superonion - ITeye技术网站
博客分类:
最近一项目需要从某高校教务处网站爬取各教学楼的教室安排数据,网址为: 。
用firebug监视,点击页面上的“查询”按钮后,发现请求url是被加密过的,无法获取。后经人指点,可用Watij (Web Application Testing in Java) 来模拟网页控件操作,获取数据。
Watij支持模拟IE、FireFox,我用的是FireFox,需要从官网上 下载webspec_xxx.zip,解压,然后把java/dist/目录下的webspec.jar以及lib/目录下的全部jar包引入工程。
代码如下:
package org.itec.
import java.io.BufferedW
import java.io.F
import java.io.FileW
import org.watij.webspec.dsl.T
import org.watij.webspec.dsl.WebS
public class WatijClassroom {
private static String homepage = "http://202.114.5.131/index.aspx";
//教学楼对应value值,西十二8,东九7,西五5,东十二1
private static String[] building = {"W12", "E9", "W5", "E12"};
private static String[] buildingValue = {"8", "7", "5", "1"};
private static String filePath = "D:\\Classroom\\";
public static void main(String[] args) throws Exception {
//打开网页
WebSpec spec = new WebSpec().mozilla();
spec.open(homepage);
for (int i = 0; i & 4; i ++) {
System.out.println("Fetching data of building " + building[i]);
spec.find.select().with.id("Build").set("value", buildingValue[i]);//选择教学楼
spec.find.input().with.name("btnRightall").click();//选择所有教室
spec.find.input().with.name("Button1").click();//点击查询
int page = 0;
Tag tag = spec.find.a().with.innerText("后页");
//下载所有页的网页
while (tag.exists()) {
file = new File(filePath, building[i] + "/" + page + ".html");
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
System.out.println("Downloading page " + page + " ...");
String htmlString = spec.source();
// get the brower's source as a html string
bw.write(htmlString);
bw.close();
tag.click();
tag = spec.find.a().with.innerText("后页");
System.out.println("All the pages have been downloaded.");
注:代码参考此文:
运行后如下图:
superonion
浏览: 92862 次
来自: 武汉
我觉得对于开发者来说,能脚本化编写爬虫是一件挺开心的事情( ̄▽ ...
请问怎么设置才不是自动播放啊,为什么我一运行就是自动播放啊。。 ...
这个有点抖动,不知道怎么去抖动啊?将线程睡眠时间降低也不行,可 ...
Instance方法上应该加上同步锁 方法名小写java之爬虫:爬取网页源代码 - 博客频道 - CSDN.NET
祥子的博客
分类:java
package com.dx.
import java.io.BufferedInputS
import java.io.BufferedR
import java.io.IOE
import java.io.InputS
import java.io.InputStreamR
import java.net.URL;
import java.net.URLC
public class CrawlerUtil {
* 获取源代码
public static String getHtmlSource(String url){
InputStream inputStream =
BufferedReader in =
StringBuilder htmlSource= new StringBuilder();
//1.获取网址
URL u = new URL(url);
//2.打开连接
URLConnection conn = u.openConnection();
//3.获取输入流
inputStream = conn.getInputStream();
//4.将源代码写入内存(设置编码)
in = new BufferedReader(new InputStreamReader(inputStream,&utf-8&));
String str = &&;
while((str = in.readLine()) != null){
htmlSource.append(str);
} catch (Exception e) {
e.printStackTrace();
if(in != null)in.close();
if(inputStream != null)inputStream.close();
} catch (IOException e) {
e.printStackTrace();
return htmlSource.toString();
public static void main(String[] args) {
String url = &/&;
System.out.println(getHtmlSource(url));
排名:千里之外
(53)(2)(1)(5)(1)(16)(11)(12)(8)(7)(2)(2)(22)(2)(9)(6)(3)(1)(1)(6)(20)(2)(1)(2)(1)(0)(35)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(1)(2)(4)(0)(1)(2)(2)(1)(3)(1)(1)(1)(1)(1)(3)(1)(1)}

我要回帖

更多关于 桌面图标不在主显示器 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信