想要免费看小说吗?
来源:互联网 发布:外国人淘宝开店 编辑:程序博客网 时间:2024/04/27 20:37
很多人找不到想要看的小说,今天就教大家一种方法,写个爬虫直接完事,啥都不说了上代码
package com.cn.love.ui;import java.io.DataOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.OutputStreamWriter;import java.io.UnsupportedEncodingException;import java.io.Writer;import java.util.ArrayList;import java.util.List;import java.util.Map;import org.apache.http.HttpHost;import org.apache.http.HttpResponse;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.conn.params.ConnRoutePNames;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.params.CoreConnectionPNames;import org.apache.http.util.EntityUtils;import org.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.nodes.Element;import org.jsoup.select.Elements;public class HttpclientJsoup {/** * Httpclient负责发送请求 * Jsoup负责解析 * @param args * @throws IOException * @throws ClientProtocolException */public static void main(String[] args) throws ClientProtocolException, IOException {//创建httpClient对象HttpClient httpClient = new DefaultHttpClient();//设置响应时间,设置传输代码时间,设置服务器 链接超时 传输超时代理服务器//httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000).setParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("124.88.67.52",83));//创建get请求 3406013 68章 3432974String url="";HttpGet httpGet=new HttpGet("http://www.17k.com/list/493239.html");//HttpGet httpGet=new HttpGet("http://www.readnovel.com/novel/120040.html");//向百度服务器发送请求,获取网页源码HttpResponse response = httpClient.execute(httpGet);//EntityUtils工具类把网页实体转换成字符串String content = EntityUtils.toString(response.getEntity(), "utf-8");//拿到网页内容了 开始解析Document doc = Jsoup.parse(content);//使用元素选择器选择 网页内容Elements a= doc.select(".Main .Volume dd a");for (int i = 0; i < a.size(); i++) {Element eurl = a.get(i);url="http://www.17k.com/"+eurl.attr("href");HttpGet httpGet1=new HttpGet(url);HttpResponse response1 = httpClient.execute(httpGet1);String content1 = EntityUtils.toString(response1.getEntity(), "utf-8");Document doc1 = Jsoup.parse(content1);Elements es= doc1.select("h1");Elements qw= doc1.select(".p #chapterContentWapper");//System.out.println(es);//for (Element e:es) {//System.out.println(e.text()+":"+e.attr("href"));//}File file = new File("D:" + File.separator + "修罗武神.txt"); try { // 注意,这个地方,那个true的参数,代表如果这个文件已经存在了,就把新的内容添加到该文件的最后 // 如果你想重新创建新文件,把true改成false就好了 Writer writer = new OutputStreamWriter(new FileOutputStream(file, true), "UTF-8"); StringBuilder builder = new StringBuilder(); for (int j = 0; j < es.size(); j++) {Element h1 = es.get(j);Element test = qw.get(j);System.out.println(h1.text());System.out.println(test.text());builder.append(h1.text());builder.append("\r\n");builder.append(test.text());builder.append("\r\n"); } writer.write(builder.toString()); writer.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}}}
0 0
- 想要免费看小说吗?
- 免费的图书馆的后门,可以看电子书小说
- 想要免费的JSP/Servlet空间吗?
- 想要看别人的歌吗
- 喜欢看小说。。。
- 现在看什么小说
- 我看的小说
- 看小说的感触!
- myeclipse console看小说
- 控制台天涯看小说
- 免费的英语 小说 音频文件
- 想要看的文章
- 很好看的程序员小说:
- 写给程序员看的小说
- 我想要看的资料
- MONKOVEL-安卓端免费的小说阅读器
- IT技术图书之《敏捷无敌》当小说看 你信吗?
- 2005.03.20 / 风和日丽, 看小说, 喝酒, ...
- Python print 不换行打印
- xcode 功能
- leetcode#561 Array Partition I
- ActiveMQ故障转移传输
- static,synchronized,final这几个词的理解
- 想要免费看小说吗?
- Android Studio2.3 如何设置提示快速注释文档
- ueditor文字排版后读取错误及上传图片问题
- eclipse报错
- java引用传递和值传递的详细探讨
- java File这是文件基类,抽象地代表一个文件实体,它有四个不同的构造方法:
- Htc Vive开发注意
- Burp Suite抓HTTPS数据包(通用)
- 图像冗余信息