Skip to content

Commit 7af5ac0

Browse files
committed
增加网络爬虫部分
1 parent eb82644 commit 7af5ac0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- [JPA](./后端开发/JakartaEE/JPA.md)
5353
</details>
5454

55+
- [网络爬虫](./网络爬虫/nav.md)
5556

5657
#### 前端开发
5758
- [HTML](./前端开发/HTML.md)

网络爬虫/nav.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
>网络爬虫,是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁、自动索引、模拟程序或者蠕虫。
2+
3+
# HttpClient
4+
5+
## Get请求
6+
7+
```java
8+
HttpGet get = new HttpGet("http://www.baidu.com");
9+
10+
try (CloseableHttpClient client = HttpClients.createDefault();
11+
CloseableHttpResponse response = client.execute(get)) {
12+
String s = EntityUtils.toString(response.getEntity(), "utf8");
13+
14+
System.out.println(s);
15+
}
16+
```
17+
18+
- 设置参数
19+
20+
```java
21+
URIBuilder uriBuilder = new URIBuilder("http://www.baidu.com/s").addParameter("wd", "关键词");
22+
HttpGet get = new HttpGet(uriBuilder.build());
23+
```
24+
25+
## POST请求
26+
27+
```java
28+
var request = new HttpPost("http://example");
29+
var pairs = List.of(new BasicNameValuePair("keys", "java"), new BasicNameValuePair("keys", "python"));
30+
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs, "utf8");
31+
request.setEntity(entity);
32+
```

0 commit comments

Comments
 (0)