简体   繁体   中英

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).

When i use the driver.get(completeUrl); method, selenium opens a new firefox window with the site i refer in "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. That because the information i need is included in the first KB of a site.

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? Or can it be done with some java method?

Please Help.

There is no method in Selenium to stop downloading. 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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