您的位置:首页 > 其它

Selenium FF WebDriver 遍历所有链接(另类爬虫)

2014-11-23 21:40 337 查看
请看这个页面,我想要找到某个公告的内容,必须一个一个打开链接,尼玛好多啊。

于是,我机智的使用selenium打开每一个链接,然后把公告内容写入txt

那需要做一下步奏

1.依次打开一个公告

2.切换focus到新窗口,找到公告内容,写到txt

3.关闭该窗口

4.切换到主窗口

5.当前页面遍历完,点击下一页

6.重复步奏1

public static WebDriver getFirefoxDriver()
{
try
{
WindowsUtils.tryToKillByName("firefox.exe");
}
catch(Exception e)
{
System.out.println("can not find firefox process");
}
File file=new File("d:\\firebug-2.0.4-fx.xpi");
FirefoxProfile profile = new FirefoxProfile();

try {
profile.addExtension(file);
profile.setPreference("extensions.firebug.currentVersion", "2.0.4");
profile.setPreference("extensions.firebug.allPagesActivation", "on");
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}

WebDriver driver = new FirefoxDriver(profile);
return driver;

}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐