当前位置: 首页 > news >正文

在上海做兼职在哪个网站网址提交百度收录

在上海做兼职在哪个网站,网址提交百度收录,什么网站可以做微传单,望京做网站目录 一、爬虫的定义 二、获取数据 (1)基于Get方式的请求(无参) (2)基于Get方式请求(有参) (3)基于Post方式的请求(无参) &…

目录

一、爬虫的定义

二、获取数据

(1)基于Get方式的请求(无参)

(2)基于Get方式请求(有参)

(3)基于Post方式的请求(无参)

(4)基于Post方式的请求(有参)


一、爬虫的定义

爬虫指的是一种自动化程序,能够模拟人类在互联网上的浏览行为,自动从互联网上抓取、预处理并保存所需要的信息。


爬虫运行的过程一般是先制定规则(如指定要抓取的网址、要抓取的信息的类型等),紧接着获取该网址的HTML源代码,根据规则对源代码进行解析和抽取,最后进行处理和保存。

爬虫在实际应用中广泛使用,如搜索引擎、大数据分析、交易数据采集等领域,都需要用到爬虫技术来实现信息的定向采集和处理

关于爬虫,我们基本上可以分为两步,第一是获取数据,第二是解析数据;

二、获取数据

(1)基于Get方式的请求(无参)

public static void main(String[] args) throws IOException {CloseableHttpClient httpClient = HttpClients.createDefault();HttpGet httpGet=new HttpGet("https://www.lanqiao.cn/");//发送http中的get请求HttpEntity entity=null;CloseableHttpResponse response=null;//判断是否得到正确的数据try {response= httpClient.execute(httpGet);if(response.getStatusLine().getStatusCode()==200){//获取响应数据entity=response.getEntity();//获取的数据输出其实是个对象System.out.println(entity);//将响应数据以html源码形式展示String html = EntityUtils.toString(entity, "UTF-8");System.out.println(html);}}catch (Exception e){e.printStackTrace();}finally {try{if(response!=null)response.close();//响应成功后关闭if(httpClient!=null)httpClient.close();}catch(Exception e){e.printStackTrace();}}}

(2)基于Get方式请求(有参)

public static void main(String[] args) throws IOException {CloseableHttpClient httpClient = HttpClients.createDefault();HttpGet httpGet=new HttpGet("https://www.lanqiao.cn/");//发送http中的get请求HttpEntity entity=null;CloseableHttpResponse response=null;//判断是否得到正确的数据try {response= httpClient.execute(httpGet);if(response.getStatusLine().getStatusCode()==200){//获取响应数据entity=response.getEntity();//获取的数据输出其实是个对象System.out.println(entity);//将响应数据以html源码形式展示String html = EntityUtils.toString(entity, "UTF-8");System.out.println(html);}}catch (Exception e){e.printStackTrace();}finally {try{if(response!=null)response.close();//响应成功后关闭if(httpClient!=null)httpClient.close();}catch(Exception e){e.printStackTrace();}}}

(3)基于Post方式的请求(无参)

public class HtppClientDemo1 {public static void main(String[] args) throws IOException {CloseableHttpClient httpClient=HttpClients.createDefault();//创建post请求HttpPost httpPost=new HttpPost("https://www.lanqiao.cn/");HttpEntity entity=null;CloseableHttpResponse response=null;try{response=httpClient.execute(httpPost);if(response.getStatusLine().getStatusCode()==200){//获取响应数据entity=response.getEntity();System.out.println(entity);//网页源代码String html=EntityUtils.toString(entity,"UTF-8");System.out.println(html);}}catch(Exception e){e.printStackTrace();}finally {try{if(response!=null)response.close();if(httpClient!=null)httpClient.close();}catch (Exception e){e.printStackTrace();}}}

(4)基于Post方式的请求(有参)

public static void main(String[] args) {CloseableHttpClient httpClient = HttpClients.createDefault();//创建post请求HttpPost httpPost = new HttpPost("https://www.lanqiao.cn/");HttpEntity entity = null;CloseableHttpResponse response = null;try {//设置参数BasicNameValuePair basicNameValuePair=new BasicNameValuePair("progid","20");//装入集合List<BasicNameValuePair> list=new ArrayList<>();list.add(basicNameValuePair);//开始进行参数请求,进行网络请求UrlEncodedFormEntity urlEncodedFormEntity=new UrlEncodedFormEntity(list,"UTF-8");httpPost.setEntity(urlEncodedFormEntity);//请求参数结束response = httpClient.execute(httpPost);if (response.getStatusLine().getStatusCode() == 200) {//获取响应数据entity = response.getEntity();System.out.println(entity);//网页源代码String html = EntityUtils.toString(entity, "UTF-8");System.out.println(html);}} catch (Exception e) {e.printStackTrace();} finally {try {if (response != null) response.close();if (httpClient != null) httpClient.close();} catch (Exception e) {e.printStackTrace();}}}

http://www.hkea.cn/news/431636/

相关文章:

  • 手机网站设计制作公司微信推广费用一般多少
  • 建设网站需要什么注册域名费用一般多少钱
  • 女性门户网站源码百度指数功能有哪些
  • 怎么帮公司做网站建设谷歌搜索引擎免费入口 香港
  • 请写出网站建设前期需要做的准备外贸定制网站建设电话
  • 南京门户网站建设网络营销优秀案例
  • 2012服务器如何做网站周口网络推广哪家好
  • 贵阳搜索玩的网站网络舆情软件免费入口
  • 前端自己写代码建网站要花多少钱游戏推广在哪里接活
  • 网站建设中+网页代码nba最新排名东西部
  • 东莞企业建设网站官网有限公司百度推广深圳分公司
  • 海外推广工作内容搜索引擎优化seo是什么
  • wordpress 发短信西安网络优化大的公司
  • dreamweaver个人网站南宁求介绍seo软件
  • 网站常用素材企业培训视频
  • 北京市通州区建设委员会网站网站新站整站排名
  • 太原网站推广只选中联传媒推广排名seo
  • 企业网站建设的常见流程为百度互联网营销顾问
  • 养殖企业网站网络营销策划名词解释
  • 如何进行电子商务网站推广?百度网盘app
  • 做情趣网站需要什么资质sem推广外包
  • 国外网站做任务赚钱的最近新闻有哪些
  • 建设部网站查资质中裕隆百度推广登录平台网址
  • 黄页网站大全免费山东网络推广优化排名
  • 网站文字代码常见的网络营销工具
  • 计算机毕设网站建设怎么改长沙网站设计拓谋网络
  • 类似红盟的网站怎么做aso优化推广
  • vs2013做网站怎样制作免费网页
  • b2c网站的开发无锡网络优化推广公司
  • 网站做视频在线观看营销活动推广方案