简体   繁体   English

停止下载Selenium API中的页面

[英]Stop the download of a page in selenium API

i'm using the selenium API for a java program (http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html). 我正在将selenium API用于Java程序(http://selenium.googlecode.com/svn/trunk/docs/api/java/index.html)。

When i use the driver.get(completeUrl); 当我使用driver.get(completeUrl); method, selenium opens a new firefox window with the site i refer in "completeUrl". 方法,硒打开一个新的Firefox窗口,其中包含我在“ completeUrl”中引用的网站。

Now, there're many web sites that have videos, music and other heavy content i don't want to download while using selenium with firefox. 现在,有很多网站都包含视频,音乐和其他大量内容,而我在使用Firefox与Selenium时不想下载。 That because the information i need is included in the first KB of a site. 那是因为我需要的信息包含在站点的第一个KB中。

How can i don't lose time downloading all this content? 我如何不浪费时间下载所有这些内容? There's a method of Selenium API that allows me to stop the downloading of a web page in Firefox after some time or KB? 有一种Selenium API的方法,可以让我在一段时间或KB之后停止在Firefox中下载网页吗? Or can it be done with some java method? 还是可以使用某些Java方法来完成?

Please Help. 请帮忙。

There is no method in Selenium to stop downloading. Selenium中没有任何方法可以停止下载。 Selenium is just too strong for this sort of work, it is designed to interact with browsers and behave like a human sitting in front of the computer. 硒对于这种工作来说太强大了,它旨在与浏览器进行交互,并且表现得像坐在电脑前的人类。

If you just want the HTML code, then use the procedures found at How to fetch HTML in Java or How do you Programmatically Download a Webpage in Java . 如果您只需要HTML代码,请使用如何在Java中获取HTML如何 以Java方式以 编程方式下载网页中找到的过程

Try doing it like this: 尝试这样做:

import java.io.*;
import java.net.URL;

public class WebsiteReader{
    public static BufferedReader read(String url) throws Exception{
        return new BufferedReader(new InputStreamReader(new URL(url).openStream()));}

public static void main (String[] args) throws Exception{
    BufferedReader reader = read(args[0]);
    String line = reader.readLine();

    while (line != null) {
        System.out.println(line);
        line = reader.readLine(); }}
}

U also can take a look at this topic: Get source of website in java There should be enough info to achieve what you want. 您还可以看一下以下主题: 用Java获取网站源应该有足够的信息来实现您想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM