博客
关于我
Java爬虫.HttpClient
阅读量:320 次
发布时间:2019-03-04

本文共 621 字,大约阅读时间需要 2 分钟。

1.HttpClient

网络爬虫就是用程序帮助我们访问网络上的资源。我们一直以来都是使用HTTP协议访问互联网的网页,网络爬虫需要编写程序,在这里使用相同的HTTP协议访问网页。

这里我们使用Java的HTTP协议客户端HttpClient这个技术,来实现抓取网页数据。

1.1 GET请求

访问csdn官网,请求url地址
https://www.csdn.net/

1.2 带参数的Get请求

在慕课网中搜索学习视频,地址为:
https://www.icourse163.org/search.htm?search=java#/
Ctrl+N 查找类

1.3 POST请求

使用POST请求访问CSDN官网
*仅一处变动:
创建HttpPost对象,设置url访问地址
HttpPost httpPost = new HttpPost(uriBuilder.build());

1.4 POST含参请求

在慕课网中使用POST含参请求搜索学习视频,地址为:
https://www.icourse163.org/search
url地址没有参数,参数search=java放在表单中进行提交

1.5 连接池

如果每次请求都要创建 HttpClient ,会有频繁创建和销毁的问题,可以使用连接池来解决。

1.6 请求参数

有时候因为网络,或者目标服务器的原因,请求需要更长的时间才能完成,我们需要自定义相关时间

转载地址:http://yqhq.baihongyu.com/

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>