Java Code Examples for org.jsoup.nodes.Document#getElementById()

The following examples show how to use org.jsoup.nodes.Document#getElementById() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MissZzzReader   File: TianLaiReadUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 从html中获取章节正文
 *
 * @param html
 * @return
 */
public static String getContentFormHtml(String html) {

    Document doc = Jsoup.parse(html);
    Element divContent = doc.getElementById("content");

    if (divContent != null) {
        String content = Html.fromHtml(divContent.html()).toString();
        char c = 160;
        String spaec = "" + c;
        content = content.replace(spaec, "  ");
        return content;
    } else {
        return "";
    }
}
 
Example 2
Source Project: ripme   File: DeviantartRipper.java    License: MIT License 6 votes vote down vote up
/**
 * Returns list of Links to the Image pages. NOT links to fullsize image!!! e.g.
 * https://www.deviantart.com/kageuri/art/RUBY-568396655
 * 
 * @param page Page of album with multiple images
 * 
 */
@Override
protected List<String> getURLsFromPage(Document page) {

	List<String> result = new ArrayList<String>();

	Element div;
	if (usingCatPath) {
		div = page.getElementById("gmi-");

	} else {
		div = page.getElementsByClass("folderview-art").first().child(0);

	}
	Elements links = div.select("a.torpedo-thumb-link");

	for (Element el : links) {
		result.add(el.attr("href"));

	}

	LOGGER.info("Amount of Images on Page: " + result.size());
	LOGGER.info(page.location());

	return result;
}
 
Example 3
Source Project: astor   File: SelectorTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void testCharactersInIdAndClass() {
    // using CSS spec for identifiers (id and class): a-z0-9, -, _. NOT . (which is OK in html spec, but not css)
    String h = "<div><p id='a1-foo_bar'>One</p><p class='b2-qux_bif'>Two</p></div>";
    Document doc = Jsoup.parse(h);

    Element el1 = doc.getElementById("a1-foo_bar");
    assertEquals("One", el1.text());
    Element el2 = doc.getElementsByClass("b2-qux_bif").first();
    assertEquals("Two", el2.text());

    Element el3 = doc.select("#a1-foo_bar").first();
    assertEquals("One", el3.text());
    Element el4 = doc.select(".b2-qux_bif").first();
    assertEquals("Two", el4.text());
}
 
Example 4
Source Project: MHViewer   File: ForumsParser.java    License: Apache License 2.0 5 votes vote down vote up
public static String parse(String body) throws ParseException {
    try {
        Document d = Jsoup.parse(body, EhUrl.URL_FORUMS);
        Element userlinks = d.getElementById("userlinks");
        Element child = userlinks.child(0).child(0).child(0);
        return child.attr("href");
    } catch (Throwable e) {
        ExceptionUtils.throwIfFatal(e);
        throw new ParseException("Parse forums error", body);
    }
}
 
Example 5
Source Project: CourseScheduleDemo   File: CourseParse.java    License: MIT License 5 votes vote down vote up
public static List<Course> parsePersonal(String data){
    List<Course> courses = new ArrayList<>();
    Document doc = Jsoup.parse(data);
    //首先获取Table
    Element table = doc.getElementById("Table1");
    //然后获取table中的td节点
    Elements trs = table.select("tr");
    //移除不需要的参数,这里表示移除前两个数值。
    trs.remove(0);
    trs.remove(0);
    //遍历td节点
    for (int i=0; i<trs.size(); ++i){
        Element tr = trs.get(i);
        //获取tr下的td节点,要求
        Elements tds = tr.select("td[align]");
        //遍历td节点
        for(int j=0; j<tds.size(); ++j){
            Element td = tds.get(j);
            String str = td.text();
            //如果数值为空则不计算。
            if (str.length() != 1){
                //解析文本数据
                str = parsePersonalCourse(str);
                Course course = new Course();
                course.setClsName(str);
                course.setDay(j+1);
                course.setClsCount(Integer.valueOf(td.attr("rowspan")));
                course.setClsNum(i+1);
                Random random = new Random();
                int num = random.nextInt(COLOR.length);
                course.setColor(COLOR[num]);
                courses.add(course);
            }
        }
    }
    return courses;
}
 
Example 6
Source Project: ZfsoftCampusAssit   File: LoginParser.java    License: Apache License 2.0 5 votes vote down vote up
private void parseLoiginUser(User loginFormUser,String loginUserHtml) {
    Document userDoc = Jsoup.parse(loginUserHtml);
    Element userNameElement = userDoc.getElementById("xhxm");
    if (userNameElement != null && userNameElement.hasText()) {
        loginFormUser.userRealName = StringUtil.parseUserFieldTextHtml(userNameElement.text(), 0, 2);
    }
}
 
Example 7
private ArrayList<ApsvOrder> findOrders(String html) {
    //logger.info("Html: {}", html);
    ArrayList<ApsvOrder> orders = new ArrayList<>();

    Document doc = Jsoup.parse(html);

    Element ordersForm = doc.getElementById("J-submit-form");
    if (ordersForm == null) {
        logger.error("Cannot find order list form, maybe cookie expires");
        // 标记task status为异常
        // TODO 弹窗提醒cookie异常
        RunTasksModel.getInstance().MarkTaskException(task.id);
        return orders;
    }

    Elements tableBody = doc.select("#tradeRecordsIndex>tbody");
    Elements orderRows = tableBody.select("tr");

    orderRows.forEach(row -> {
        Elements timeNodes = row.select("td.time p");
        String[] orderNoData = row.select("td.tradeNo p").text().split("\\|");
        ApsvOrder order = new ApsvOrder(){
            {
                taskId = task.id;
                time = timeNodes.get(0).text() + " " + timeNodes.get(timeNodes.size() - 1).text();
                description = row.select(".memo-info").text();
                memo = row.select("td.memo p").text();
                tradeNo = orderNoData.length > 1 ? orderNoData[1].split(":")[1] : orderNoData[0].split(":")[1];
                username = Unicode.unicodeToString(row.select("td.other p").text());
                amount = Float.parseFloat(row.select("td.amount span").text().replaceAll("\\s+", ""));
                status = row.select("td.status p").text();
            }
        };
        order.sig = Order.Sign(order, task.pushSecret);
        orders.add(order);
    });
    return orders;
}
 
Example 8
Source Project: astor   File: SelectorTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void testCharactersInIdAndClass() {
    // using CSS spec for identifiers (id and class): a-z0-9, -, _. NOT . (which is OK in html spec, but not css)
    String h = "<div><p id='a1-foo_bar'>One</p><p class='b2-qux_bif'>Two</p></div>";
    Document doc = Jsoup.parse(h);

    Element el1 = doc.getElementById("a1-foo_bar");
    assertEquals("One", el1.text());
    Element el2 = doc.getElementsByClass("b2-qux_bif").first();
    assertEquals("Two", el2.text());

    Element el3 = doc.select("#a1-foo_bar").first();
    assertEquals("One", el3.text());
    Element el4 = doc.select(".b2-qux_bif").first();
    assertEquals("Two", el4.text());
}
 
Example 9
Source Project: VileBot   File: GetInfoOn.java    License: MIT License 5 votes vote down vote up
private String parseResponse( String response )
    throws Exception
{
    Document doc = Jsoup.parse( response );
    Element bodyDiv = doc.getElementById( "mw-content-text" );
    Element firstParagraph = bodyDiv.getElementsByTag( "p" ).first();
    String answer = firstParagraph.text();
    if ( answer.isEmpty() )
    {
        throw new Exception();
    }
    answer = answer.replaceAll( "\\[[0-9]+\\]", "" );
    return answer;
}
 
Example 10
Source Project: CourseScheduleDemo   File: CourseParse.java    License: MIT License 5 votes vote down vote up
public static boolean parseIsLoginSucceed(String data){
    Document doc = Jsoup.parse(data);
    //查看登陆文档。
    Element element = doc.getElementById("xhxm");
    if (element != null){
        return true;
    }
    return false;
}
 
Example 11
@Override
protected Collection<Asset> getNewestAssets() throws IOException {
	Document mainPage = getPage(getApiUrl());

	// Get File Name From Main Page
	Element ele = mainPage.getElementById("project-overview");
	ele = ele.getElementsContainingOwnText("Newest File").first();

	// Add zip extension to filename if author did not add it
	String fileName = ele.text().split(":")[1].trim();
	if (!fileName.toLowerCase().endsWith(".zip")){
		fileName += ".zip";
	}

	// Get Download Page Link
	String downloadPageLink = mainPage.select("ul.regular-dl a").first().absUrl("href");
	URL downloadPageUrl = new URL(downloadPageLink);

	// Get Mod Download Link from Download Page
	Document downloadPage = getPage(downloadPageUrl);
	String downloadLink = downloadPage.select("a.download-link").first().absUrl("data-href");
	URL downloadUrl = new URL(downloadLink.replace(" ", "%20"));

	// Return Asset
	Collection<Asset> assets = new LinkedList<>();
	assets.add(new Asset(fileName, downloadUrl));
	return assets;
}
 
Example 12
Source Project: v9porn   File: Parse99Mm.java    License: MIT License 5 votes vote down vote up
public static List<String> parse99MmImageList(String html) {

        Document doc = Jsoup.parse(html);

        Element elementBox = doc.getElementById("picbox");
        String imgUrl = elementBox.selectFirst("img").attr("src").trim();
        HttpUrl httpUrl = HttpUrl.parse(imgUrl);
        Element element = doc.body().select("script").first();
        String javaScript = element.toString();
        String data = StringUtils.subString(javaScript, javaScript.indexOf("[") + 1, javaScript.lastIndexOf(";") - 1);
        String[] dataArray = data.replace("\"", "").split(",");

        int imgIdArrayLength = dataArray.length - 6;

        String[] imgIdArray = new String[imgIdArrayLength];
        System.arraycopy(dataArray, 6, imgIdArray, 0, imgIdArrayLength);
        Logger.t(TAG).d(dataArray);
        Logger.t(TAG).d(imgIdArray);

        List<String> stringImageList = new ArrayList<>();
        String host;
        if (httpUrl == null) {
            host = "http://fj.kanmengmei.com/";
        } else {
            host = httpUrl.scheme() +"://"+ httpUrl.host();
        }

        for (int i = 0; i < imgIdArrayLength; i++) {
            String tmpImgUrl = host + "/" + dataArray[1] + (i + 1) + "-" + imgIdArray[i] + ".jpg";
            Logger.t(TAG).d(tmpImgUrl);
            stringImageList.add(tmpImgUrl);
        }
        return stringImageList;

    }
 
Example 13
Source Project: astor   File: SelectorTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void testCharactersInIdAndClass() {
    // using CSS spec for identifiers (id and class): a-z0-9, -, _. NOT . (which is OK in html spec, but not css)
    String h = "<div><p id='a1-foo_bar'>One</p><p class='b2-qux_bif'>Two</p></div>";
    Document doc = Jsoup.parse(h);

    Element el1 = doc.getElementById("a1-foo_bar");
    assertEquals("One", el1.text());
    Element el2 = doc.getElementsByClass("b2-qux_bif").first();
    assertEquals("Two", el2.text());

    Element el3 = doc.select("#a1-foo_bar").first();
    assertEquals("One", el3.text());
    Element el4 = doc.select(".b2-qux_bif").first();
    assertEquals("Two", el4.text());
}
 
Example 14
Source Project: HHComicViewer   File: ParsePicUrlList.java    License: Apache License 2.0 5 votes vote down vote up
private static String parsePicUrl(Document picDoc, int serverId, String encodeKey) {
    Element body = picDoc.getElementById("iBodyQ");
    Element img = body.getElementsByTag("img").first();
    String cypherText = img.attr("name");
    String serverUrl = null;
    if (serverId < 10) {
        serverUrl = HHApplication.getInstance().getHHWebVariable().getPicServer() + "0" + serverId + "/";
    } else {
        serverUrl = HHApplication.getInstance().getHHWebVariable().getPicServer() + serverId + "/";
    }
    // 进行密文的解码
    String url = unsuan(cypherText, serverId, encodeKey);
    return serverUrl + url;
}
 
Example 15
Source Project: v9porn   File: ParseV9PronVideo.java    License: MIT License 4 votes vote down vote up
/**
 * 解析登录用户信息
 *
 * @return 用户
 */
public static User parseUserInfo(String html) {
    User user = new User();
    Document doc = Jsoup.parse(html);
    //新帐号注册成功登录后信息不一样,导致无法解析
    Element element = doc.getElementById("userinfo-title");
    if (element == null) {
        user.setLogin(true);
        user.setUserName("无法解析用户信息...");
        return user;
    }

    //解析用户uid,2018年3月29日 似乎已经失效了,可在播放界面获取
    Element userLickElement = element.select("a").first();
    if (userLickElement != null) {
        String userLinks = userLickElement.attr("href");
        int uid = Integer.parseInt(StringUtils.subString(userLinks, userLinks.indexOf("=") + 1, userLinks.length()));
        user.setUserId(uid);
        Logger.t(TAG).d(userLinks);
        Logger.t(TAG).d(uid);
    } else {
        Logger.t(TAG).d("无法解析用户uid");
    }
    String userInfoTitle = doc.getElementById("userinfo-title").text();
    String userName = StringUtils.subString(userInfoTitle, userInfoTitle.indexOf("欢迎") + 3, userInfoTitle.indexOf("用户状态"));
    Logger.t(TAG).d(userName);
    user.setUserName(userName);

    String userAccountStatus = doc.getElementById("userinfo-title").select("font").first().text();
    Logger.t(TAG).d(userAccountStatus);
    user.setStatus(userAccountStatus);

    String userContent = doc.getElementById("userinfo-content").text();
    Logger.t(TAG).d(userContent);

    String lastLoginTime = userContent.substring(userContent.indexOf("最后登录"), userContent.indexOf("IP:"));
    String lastLoginIP = userContent.substring(userContent.indexOf("IP:"), userContent.indexOf("点此查看"));
    user.setLastLoginTime(lastLoginTime);
    user.setLastLoginIP(lastLoginIP);

    Logger.t(TAG).d(lastLoginTime);
    Logger.t(TAG).d(lastLoginIP);

    return user;
}
 
Example 16
Source Project: v9porn   File: Parse99Mm.java    License: MIT License 4 votes vote down vote up
public static BaseResult<List<Mm99>> parse99MmList(String html, int page) {
    BaseResult<List<Mm99>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Logger.t(TAG).d(html);
    Document doc = Jsoup.parse(html);
    Element ul = doc.getElementById("piclist");
    Elements lis = ul.select("li");
    List<Mm99> mm99List = new ArrayList<>();
    for (Element li : lis) {
        Mm99 mm99 = new Mm99();
        Element a = li.selectFirst("dt").selectFirst("a");
        String contentUrl = "http://www.99mm.me" + a.attr("href");
        mm99.setContentUrl(contentUrl);

        int startIndex = contentUrl.lastIndexOf("/");
        int endIndex = contentUrl.lastIndexOf(".");
        String idStr = StringUtils.subString(contentUrl, startIndex + 1, endIndex);

        if (!TextUtils.isEmpty(idStr) && TextUtils.isDigitsOnly(idStr)) {
            mm99.setId(Integer.parseInt(idStr));
        } else {
            Logger.t(TAG).d(idStr);
        }

        Element img = a.selectFirst("img");
        String title = img.attr("alt");
        mm99.setTitle(title);
        String imgUrl = img.attr("src");
        HttpUrl httpUrl = HttpUrl.parse(imgUrl);
        if (httpUrl == null) {
            imgUrl = img.attr("data-img");
        }
        Logger.t(TAG).d("图片链接::" + imgUrl);
        mm99.setImgUrl(imgUrl);
        int imgWidth = Integer.parseInt(img.attr("width"));
        mm99.setImgWidth(imgWidth);

        mm99List.add(mm99);
    }

    if (page == 1) {
        Element pageElement = doc.getElementsByClass("all").first();
        if (pageElement != null) {
            String pageStr = pageElement.text().replace("...", "").trim();
            if (!TextUtils.isEmpty(pageStr) && TextUtils.isDigitsOnly(pageStr)) {
                baseResult.setTotalPage(Integer.parseInt(pageStr));
            } else {
                Logger.t(TAG).d(pageStr);
            }
        }
    }

    baseResult.setData(mm99List);
    return baseResult;
}
 
Example 17
public static void extractComment(String url, String content, Connection conn) {
    System.out.println("==========Parse Comment:" + url + "============");
    String sql = null;
    ResultSet rs = null;
    PreparedStatement pstmt = null;
    Statement stmt = null;
    //parse comment page
    Pattern commentPattern = Pattern.compile(Constants.COMMENT_REGULAR_EXP);
    Matcher commentMatcher = commentPattern.matcher(url);
    if (commentMatcher.find()) {
        Document commentDoc = Jsoup.parse(content);
        if (commentDoc.getElementById("comments") != null) { // add to avoid exception like https://movie.douban.com/subject/25842478/comments
            Elements commentsElements = commentDoc.getElementById("comments").children();
            comments = new Comments(commentId++);
            for (Element comment : commentsElements) {
                if (comment.getElementsByClass("fold-bd").size() < 1 && comment.children().get(1).getElementsByTag("p").size() > 0) {
                    // to make sure the current item is the comment item rather than other info item      &&      检测fold-bd是查看是否有折叠,如果是折叠的评论则有fold-bd,折叠评论是指账号有异常的
                    String[] movies = commentDoc.getElementsByTag("h1").text().replace(" ", "").split("短评");
                    String commentForMovie = null;
                    for (String movie : movies) {
                        commentForMovie = movie;
                    }
                    comments.setCommentForMovie(commentForMovie);
                    comments.setCommentInfo(comment.children().get(1).getElementsByTag("p").text());//use "comment.children().get(1).text()" can get all commentInfo like "1819 有用 桃桃淘电影 2016-10-29 即便评分再高也完全喜欢不来。我们还是太热衷主题与意义了,以至于忽视了传递主题的方式与合理性。影片为了所谓的人性深度,而刻意设计剧情和人物转折,忽视基本的人物行为轨迹,都非常让人不舒服。喜欢有深度的电影,但希望能以更巧妙的方式讲出来,而不该是现在这样。以及形式上,这不就是舞台搬演么"
                    if (comment.getElementsByAttributeValue("class", "votes pr5").text().length() > 0) {
                        comments.setCommentVote(Integer.parseInt(comment.getElementsByAttributeValue("class", "votes pr5").text()));
                    }
                    comments.setCommentAuthor(comment.getElementsByAttribute("href").get(2).text());
                    comments.setCommentAuthorImgUrl(comment.getElementsByAttribute("href").get(2).attr("href"));

                    //save comment record
                    try {
                        sql = "SELECT * FROM comments WHERE commentInfo = '" + comments.getCommentInfo() + "'";
                        stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
                        rs = stmt.executeQuery(sql);

                        if (rs.next()) {
                            System.out.println(comments.getCommentAuthor() + "'s comment has been saved!!!");
                        } else {
                            //if the link does not exist in the database, insert it
                            sql = "INSERT INTO comments (commentInfo, commentAuthor, commentAuthorImgUrl, commentVote, commentForMovie) VALUES " +
                                    "('" + comments.getCommentInfo() + "','" + comments.getCommentAuthor() + "', '" + comments.getCommentAuthorImgUrl() + "'" +
                                    ", '" + comments.getCommentVote() + "', '" + comments.getCommentForMovie() + "')";
                            pstmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                            pstmt.execute();
                            System.out.println(">>>>>>saving comment for " + comments.getCommentForMovie() + " by:" + comments.getCommentAuthor() + "<<<<<<");
                        }
                    } catch (SQLException e) {
                        //handle the exceptions
                        System.out.println("SQLException: " + e.getMessage());
                        System.out.println("SQLState: " + e.getSQLState());
                        System.out.println("VendorError: " + e.getErrorCode());
                    } finally {
                        //close and release the resources of PreparedStatement, ResultSet and Statement
                        if (pstmt != null) {
                            try {
                                pstmt.close();
                            } catch (SQLException e2) {
                            }
                        }
                        pstmt = null;

                        if (rs != null) {
                            try {
                                rs.close();
                            } catch (SQLException e1) {
                            }
                        }
                        rs = null;

                        if (stmt != null) {
                            try {
                                stmt.close();
                            } catch (SQLException e3) {
                            }
                        }
                        stmt = null;
                    }
                }

            }
        }
    }
}
 
Example 18
Source Project: v9porn   File: ParseV9PronVideo.java    License: MIT License 4 votes vote down vote up
/**
     * 解析作者更多视频
     *
     * @param html html
     * @return list
     */
    public static BaseResult<List<V9PornItem>> parseAuthorVideos(String html) {
        int totalPage = 1;
        List<V9PornItem> v9PornItemList = new ArrayList<>();
        Document doc = Jsoup.parse(html);
//        Element body = doc.getElementById("leftside");

        Elements videos = doc.select("div[class=col-xs-12 col-sm-4 col-md-3 col-lg-3]");
        //doc.select("div[class=col-xs-12 col-sm-4 col-md-3 col-lg-3]").get(0).select("span[class=video-title title-truncate m-t-5]").text();

        for (Element element : videos) {

            V9PornItem v9PornItem = new V9PornItem();

            String contentUrl = element.select("a").first().attr("href");

            String viewKey = contentUrl.substring(contentUrl.indexOf("=") + 1, contentUrl.length());
            v9PornItem.setViewKey(viewKey);
            //Logger.t(TAG).d(viewKey);

            String title = element.select("span[class=video-title title-truncate m-t-5]").text();
            v9PornItem.setTitle(title);
            //Logger.t(TAG).d(title);

            String imgUrl = element.select("img[class=img-responsive]").attr("src");
            v9PornItem.setImgUrl(imgUrl);
            //Logger.t(TAG).d(imgUrl);

            String allInfo = element.text();
            //Logger.t(TAG).d(allInfo);

            String duration = element.select("span[class=duration]").text();
            v9PornItem.setDuration(duration);
            //Logger.t(TAG).d(duration);

            //String info = allInfo.substring(allInfo.indexOf("添加时间"), allInfo.length());
            v9PornItem.setInfo(element.select("span[class=info]").get(0).text());
            //Logger.t(TAG).d(info);

            v9PornItemList.add(v9PornItem);
        }

        //总页数
        Element pagingnav = doc.getElementById("paging");
        Elements a = pagingnav.select("span[class=pagingnav]");
        if (a.size() >= 2) {
            String ppp = a.get(a.size() - 2).text();
            if (TextUtils.isDigitsOnly(ppp)) {
                totalPage = Integer.parseInt(ppp);
                //Logger.d("总页数:" + totalPage);
            }
        }

        BaseResult<List<V9PornItem>> baseResult = new BaseResult<>();
        baseResult.setTotalPage(totalPage);
        baseResult.setData(v9PornItemList);

        return baseResult;
    }
 
Example 19
Source Project: v9porn   File: ParseProxy.java    License: MIT License 4 votes vote down vote up
public static BaseResult<List<ProxyModel>> parseXiCiDaiLi(String html, int page) {
    BaseResult<List<ProxyModel>> baseResult = new BaseResult<>();
    baseResult.setTotalPage(1);
    Document doc = Jsoup.parse(html);

    Element ipList = doc.getElementById("ip_list");
    Elements trs = ipList.select("tr");
    int trSize = trs.size();
    List<ProxyModel> proxyModelList = new ArrayList<>();
    for (int i = 0; i < trSize; i++) {
        //第一是标题,跳过
        if (i == 0) {
            continue;
        }
        //tr里的td
        Elements tds = trs.get(i).select("td");
        ProxyModel proxyModel = new ProxyModel();
        for (int j = 0; j < tds.size(); j++) {
            Element td = tds.get(j);
            switch (j) {
                case 0:
                    //国家
                    break;
                case 1:
                    //ip
                    String ip = td.text();
                    proxyModel.setProxyIp(ip);
                    break;
                case 2:
                    //端口
                    String port = td.text();
                    proxyModel.setProxyPort(port);
                    break;
                case 3:
                    //城市
                    break;
                case 4:
                    //匿名度
                    String anonymous = td.text();
                    proxyModel.setAnonymous(anonymous);
                    break;
                case 5:
                    //类型 http https socket
                    String type = td.text();
                    if ("http".equalsIgnoreCase(type)) {
                        proxyModel.setType(ProxyModel.TYPE_HTTP);
                    } else if ("https".equalsIgnoreCase(type)) {
                        proxyModel.setType(ProxyModel.TYPE_HTTPS);
                    } else {
                        proxyModel.setType(ProxyModel.TYPE_SOCKS);
                    }
                    break;
                case 6:
                    //速度
                    break;
                case 7:
                    //连接时间
                    String responseTime = td.select("div").first().attr("title");
                    proxyModel.setResponseTime(responseTime);
                    break;
                case 8:
                    //存活时间
                    break;
                case 9:
                    //验证时间
                    break;
                default:
            }
        }
        proxyModelList.add(proxyModel);
    }
    baseResult.setData(proxyModelList);
    if (page == 1) {
        Elements elements = doc.getElementsByClass("pagination").first().select("a");
        if (elements.size() > 3) {
            String totalPageStr = elements.get(elements.size() - 2).text();
            Logger.t(TAG).d(totalPageStr);
            if (TextUtils.isDigitsOnly(totalPageStr)) {
                baseResult.setTotalPage(Integer.parseInt(totalPageStr));
            }
        }
    }
    return baseResult;
}
 
Example 20
@Override
    public void login() {
        loginsuccessful = false;
        try {
            initialize();

            NULogger.getLogger().info("Trying to log in to Keep2Share.cc");
            httpPost = new NUHttpPost("http://keep2share.cc/login.html");
            
            Document doc = Jsoup.parse(NUHttpClientUtils.getData("http://keep2share.cc/login.html", httpContext));
            
            if(doc.getElementById("captcha_auth0") != null){
                activatedCaptcha = true;
                captchaAddress = "http://keep2share.cc" + doc.getElementById("captcha_auth0").attr("src");
            }
            
            List<NameValuePair> formparams = new ArrayList<NameValuePair>();
            
            formparams.add(new BasicNameValuePair("LoginForm[password]", getPassword()));
            formparams.add(new BasicNameValuePair("LoginForm[rememberMe]", "0"));
            formparams.add(new BasicNameValuePair("LoginForm[username]", getUsername()));
            
            if(activatedCaptcha){
                Captcha captcha = captchaServiceProvider().newCaptcha();
                captcha.setFormTitle(Translation.T().captchacontrol()+" ("+ getHOSTNAME()  +")");
                captcha.setImageURL(captchaAddress);
                captcha.setHttpContext(httpContext);
                String captchaString = captcha.getCaptchaString();

                formparams.add(new BasicNameValuePair("LoginForm[verifyCode]", captchaString));
//                formparams.add(new BasicNameValuePair("recaptcha_challenge_field", captcha.getCCaptchaUrl()));
//                formparams.add(new BasicNameValuePair("recaptcha_response_field", captchaString));
                formparams.add(new BasicNameValuePair("yt0", ""));
            }
            
            UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
            httpPost.setEntity(entity);
            httpResponse = httpclient.execute(httpPost, httpContext);
            NULogger.getLogger().info(httpResponse.getStatusLine().toString());
            
            responseString = EntityUtils.toString(httpResponse.getEntity());
            
            if(responseString.contains("Incorrect username or password")){
                throw new NUInvalidLoginException(getUsername(), getHOSTNAME());
            }
            
            if(responseString.contains("The verification code is incorrect.")){
                throw new NUCaptchaException(getHOSTNAME());
            }
            
            if(CookieUtils.existCookie(httpContext, "sessid")){
                loginsuccessful = true;
                username = getUsername();
                password = getPassword();
                hostsAccountUI().hostUI(HOSTNAME).setEnabled(true);
                NULogger.getLogger().info("Keep2Share.cc login successful!");
            } else {
                //Get error message
                responseString = EntityUtils.toString(httpResponse.getEntity());
                //FileUtils.saveInFile("KeepTwoShareAccount.html", responseString);

                //Generic exception
                throw new Exception("Generic login error");
            }
        } catch(NUException ex){
            resetLogin();
            ex.printError();
            accountUIShow().setVisible(true);
        } catch (Exception e) {
            resetLogin();
            NULogger.getLogger().log(Level.SEVERE, "{0}: {1}", new Object[]{getClass().getName(), e});
            showWarningMessage( Translation.T().loginerror(), HOSTNAME);
            accountUIShow().setVisible(true);
        }

    }