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

创意经济型网站建设谷歌ads广告投放

创意经济型网站建设,谷歌ads广告投放,网站开发岗位说明书,旅游网站建站目录 一、爬虫的定义 二、获取数据 (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/337613/

相关文章:

  • php网站后台进不去百度推广入口官网
  • 个人网站一键生成免费推广网站有哪些
  • 厦门做网站设计电商seo优化
  • wordpress视频点播seo技术是干什么的
  • 网站推广是怎么做的网络营销专业如何
  • 平面设计线上兼职上海网站seo
  • 个性化网站定制价格今日热点
  • 做网站的艰辛免费个人网站申请
  • 网站改版需要多久网站设计与制作毕业论文范文
  • 深圳横岗网站建设网站建设的推广渠道
  • 有没有什么网站免费做名片2023年新闻小学生摘抄
  • 新网金商网站外链查询工具
  • 网站建设的进度竞价托管选择微竞价
  • 网站快速网站推广怎么做一个公司网站
  • 旅游网站模板htmlseo品牌优化整站优化
  • 方圆网站建设aso优化重要吗
  • 做购实惠网站的意义好用的搜索引擎有哪些
  • 怎么把自己笔记本做服务器做个网站搭建网站基本步骤
  • jeecms做企业网站成都网站建设公司排名
  • 沈阳招聘网站开发地推项目平台
  • 798艺术区成都seo达人
  • 平度网站建设抖音代运营收费详细价格
  • 株洲网站优化找哪家seo优化的价格
  • 找印度人做网站sem竞价推广公司
  • 山西网站推广公司网站关键词优化怎么弄
  • 微信分销是什么重庆优化seo
  • 武汉企业网站推广方案永久免费无代码开发平台网站
  • 网站开发岗位群怎样推广产品
  • 桐城市美丽乡村建设专题网站石家庄整站优化技术
  • 北京建网站的公司哪个比较好郑州seo价格