package 网络编程;

 import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL; public class TestBaidu {
public static void main(String[] args) throws IOException {
URL url=new URL("http://www.baidu.com");
/*此方法会有乱码输出
InputStream is=url.openStream();
byte[] b=new byte[1024];
int len=0;
while((len=is.read(b))!=-1){
System.out.println(new String(b,0,len));
}
*/
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream(),"utf-8"));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream("baidu.html"),"utf-8"));
String str=null;
while((str=br.readLine())!=null){
bw.append(str);
bw.newLine();
}
//System.out.print(str);
bw.flush();
bw.close();
br.close();
}
}

抓取页面内容

 package 网络编程;

 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
import java.util.regex.Pattern; public class Get163URL {
public static void main(String[] args) throws IOException {
URL url=new URL("http://www.163.com");
BufferedReader br=new BufferedReader(new InputStreamReader(url.openStream(),Charset.forName("gbk")));
StringBuffer sb=new StringBuffer();
String tmp=null;
while((tmp=br.readLine())!=null){
sb.append(tmp);
}
// System.out.println(sb.toString());
Pattern p=Pattern.compile("\"(http:\\/\\/.+?)\"");
Matcher m=p.matcher(sb);
while(m.find())
System.out.println(m.group(1));
}
}

提出链接


 public class WikiDownload {
static final String name = "username";
static final String pwd = "password"; public static void main(String[] args){
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
String wikiUrl = "http://wiki.xxxxx.org/pages/viewpage.action?pageId=71709153";
String loginUrl = "http://wiki.xxxxx.org/login.action?os_destination=%2Fpages%2Fviewpage.action%3FpageId%3D71709153";
try{
URL url = new URL(loginUrl);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36");
String line;
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
try(OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream())){
writer.write("os_username=" + name
+"&os_password="+ pwd
+ "&login=%E7%99%BB%E5%BD%95&os_destination="
+ URLEncoder.encode(wikiUrl.split("http://wiki.xxxxx.org")[0],"utf-8"));
}
try(InputStreamReader reader = new InputStreamReader(connection.getInputStream())){
BufferedReader in = new BufferedReader(reader);
StringBuilder result= new StringBuilder("");
while ((line = in.readLine()) != null) {
result.append("\n");
result.append(line);
}
System.out.println(result);
}
}catch (Exception e){
e.printStackTrace();
} } }

获取需要登录的网页

【java】抓取页面内容,提取链接(此方法可以http get无需账号密码的请求)的更多相关文章

  1. 如何使用angularjs实现抓取页面内容

    <html ng-app="myApp"> <head> <title>angularjs-ajax</title> <scr ...

  2. PHP cURL库函数抓取页面内容

    目录 1 为什么要用cURL? 2 启用cURL 3 基本结构 4 检查错误 5 获取信息 6 基于浏览器的重定向 7 用POST方法发送数据 8 文件上传 9 cURL批处理(multi cURL) ...

  3. nodejs抓取页面内容,并分析有无某些内容的js文件

    nodejs获取网页内容绑定data事件,获取到的数据会分几次相应,如果想全局内容匹配,需要等待请求结束,在end结束事件里把累积起来的全局数据进行操作! 举个例子,比如要在页面中找有没有www.ba ...

  4. C#使用CSS选择器抓取页面内容

    最近在查wpf绘图资料时,偶然看到Python使用CSS选择器抓取网页的功能.觉得很强,这里用C#也实现一下. 先介绍一下CSS选择器 在 CSS 中,选择器是一种模式,用于选择需要添加样式的元素. ...

  5. Java爬虫系列二:使用HttpClient抓取页面HTML

    爬虫要想爬取需要的信息,首先第一步就要抓取到页面html内容,然后对html进行分析,获取想要的内容.上一篇随笔<Java爬虫系列一:写在开始前>中提到了HttpClient可以抓取页面内 ...

  6. 基于puppeteer模拟登录抓取页面

    关于热图 在网站分析行业中,网站热图能够很好的反应用户在网站的操作行为,具体分析用户的喜好,对网站进行针对性的优化,一个热图的例子(来源于ptengine) 上图中能很清晰的看到用户关注点在那,我们不 ...

  7. Python抓取视频内容

    Python抓取视频内容 Python 是一种面向对象.解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年.Python语法简洁而清晰,具 ...

  8. 爬虫抓取页面数据原理(php爬虫框架有很多 )

    爬虫抓取页面数据原理(php爬虫框架有很多 ) 一.总结 1.php爬虫框架有很多,包括很多傻瓜式的软件 2.照以前写过java爬虫的例子来看,真的非常简单,就是一个获取网页数据的类或者方法(这里的话 ...

  9. 用PHP抓取页面并分析

    在做抓取前,记得把php.ini中的max_execution_time设置的大点,不然会报错的.

随机推荐

  1. [转]Spring.Net介绍

    转自:http://www.cnblogs.com/cilence/archive/2013/02/21/2920478.html Spring.NET下载地址:http://www.springfr ...

  2. swizzle method 和消息转发机制的实际使用

    我的工程结构,如图 1-0 图  1-0 在看具体实现以前,先捋以下 实现思路. ViewController 中有一个-(void)Amethod;A方法. -(void)Amethod{ NSLo ...

  3. jfinal 源码学习

    源由 最近闲来无事,顺带看了下jfinal的源码,以下均为自己的个人理解,如有错误请指定: jfinal 使用 在web.xml中配置JfinalFilter 并定义JfinalConfig的类 自定 ...

  4. Hangfire在ASP.NET CORE中的简单实现

    hangfire是执行后台任务的利器,具体请看官网介绍:https://www.hangfire.io/ 新建一个asp.net core mvc 项目 引入nuget包 Hangfire.AspNe ...

  5. 深度解析continue,break和return

    continue,break和return是Java中的关键字,在方法体内的流程控制中使用频率较高. 在现实中,经常会有同学在使用中产生混淆,从而使得流程控制语句发生混乱.在这里,我结合个人的使用经历 ...

  6. azure上连续部署web

    连续部署web   连续部署web,可以在第一次部署完web应用后,方便修改和自动提交代码部署新版本的web应用.其中自动提交使用github中的webhook,使代码在master上提交修改后可以自 ...

  7. 【转】Visual Studio Code 使用Git进行版本控制

    原文链接:https://www.cnblogs.com/xuanhun/p/6019038.html?utm_source=tuicool&utm_medium=referral 本来认为此 ...

  8. linux磁盘管理系列-LVM的使用

    LVM是什么 LVM是Linux操作系统的逻辑卷管理器. 现在有两个Linux版本的LVM,分别是 LVM1,LVM2.LVM1是一种已经被认为稳定了几年的成熟产品,LVM2 是最新最好的LVM版本. ...

  9. 高可用的Spring FTP上传下载工具类(已解决上传过程常见问题)

    前言 最近在项目中需要和ftp服务器进行交互,在网上找了一下关于ftp上传下载的工具类,大致有两种. 第一种是单例模式的类. 第二种是另外定义一个Service,直接通过Service来实现ftp的上 ...

  10. C#.Net与MATLAB集成

    在数学分析工具方面,MATLAB无疑是佼佼者,除了作为软件工具外,MATLAB的自定义编程语言以及混合编程的支持,使其可以与Python.R之类数学分析语言媲美.尤其是在一些传统领域的研究,由于其研究 ...