22 封装HttpClient

老大夫 发布于 2023-01-20 16:03
HttpUtils 老教程已经进不去京东了,因为直接爬取会被拦截到京东登录页. 我们需要进行请求头伪装. 1. 到搜索页面F12 -----> network---->获取信息复制 2. 到https://curlconverter.com/java/ 直接转成HttpGet设置代码 package cn.itcast.jd.util; ...

21 编写案例的引导类,Service,Dao,Pojo

老大夫 发布于 2023-01-20 14:07
引导类 package cn.itcast.jd; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.schedu...

20 开发准备

老大夫 发布于 2023-01-18 11:05
POM文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi...

19 idea工程文件打包

老大夫 发布于 2023-01-18 10:39
地址: itcast-crawler-first.zip

18 selector选择器的组合使用获取元素

老大夫 发布于 2023-01-18 09:08
5.2.7. Selector选择器组合使用 el#id: 元素+ID,比如: h3#city_bj el.class: 元素+class,比如: li.class_a el[attr]: 元素+属性名,比如: span[abc] 任意组合: 比如:span[abc].s_name ancestor child: 查找某个元素下子元素,比如:.city_c...

17 使用选择器获取元素

老大夫 发布于 2023-01-17 22:54
Selector选择器概述 tagname: 通过标签查找元素,比如:span id: 通过ID查找元素,比如:# city_bj .class: 通过class名称查找元素,比如:.class_a 测试类文件 @Test public void testSelector()throws Exception{ //解析html...

16 获取元素中的数据

老大夫 发布于 2023-01-17 22:24
元素中获取数据 从元素中获取id 从元素中获取className 从元素中获取属性的值attr 从元素中获取所有属性attributes 从元素中获取文本内容text 测试类文件 @Test public void testData()throws Exception{ //解析文件,获取document Docu...

15 使用DOM的方式获取文档

老大夫 发布于 2023-01-17 20:32
使用dom方式遍历文档 元素获取 根据id查询元素getElementById 根据标签获取元素getElementsByTag 根据class获取元素getElementsByClass 根据属性获取元素getElementsByAttribute 测试类文件 @Test public void testDOM()throws Except...

14 Jsoup解析文件

老大夫 发布于 2023-01-17 20:30
Test测试类文件 @Test public void testFile()throws Exception{ //解析文件 Document doc = Jsoup.parse(new File("C:\\Users\\16259\\Desktop\\test.html"),"utf8"); Str...

13 jsoup解析字符串

老大夫 发布于 2023-01-17 19:59
测试类文件 @Test public void testString()throws Exception{ //使用工具类获取字符串 String content = FileUtils.readFileToString(new File("C:\\Users\\16259\\Desktop\\test.html")...

12 Jsoup解析Url

老大夫 发布于 2023-01-17 18:05
类文件 HttpClient适合于抓取数据,Jsoup适合解析数据,所以都要学习. package jsoup; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.junit.Test; import java.net.URL; public class JsoupF...

10 HttpClient-----请求参数

老大夫 发布于 2023-01-17 18:02
类文件 可以给请求设置多种参数,例如创建连接的最长时间,获取连接的最长时间,设置数据传输的最长时间 package cn.itcast.crawler.test; import jdk.nashorn.internal.ir.RuntimeNode; import org.apache.hc.client5.http.classic.methods.Htt...

09 HttpClient----连接池

老大夫 发布于 2023-01-17 17:40
类文件 注意由于交给连接池管理HttpClient了,所以我们在doGet方法中不要自己关闭HttpClient package cn.itcast.crawler.test; import org.apache.hc.client5.http.classic.methods.HttpGet; import org.apache.hc.client5.ht...

HttpClient发起请求ClientProtocolException和Target host is not specified问题分析

老大夫 发布于 2023-01-17 15:13
原因: 使用httpClient访问时,地址忘了加 http:// 协议了 解决方法: 在网址前加上http:// 引用 https://blog.csdn.net/Imobama/article/details/92794758

08 HttpCLient-----post带参数访问

老大夫 发布于 2023-01-17 14:35
类文件 这节课的地址不能用了,所以post请求返回的的不是200而是403 package cn.itcast.crawler.test; import com.sun.org.glassfish.gmbal.NameValue; import org.apache.hc.client5.http.classic.methods.HttpPost; imp...