Skip to content

Commit

Permalink
order adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-hxl committed Jan 31, 2023
1 parent 6e2947d commit b2e9f07
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 118 deletions.
100 changes: 50 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Create a crawler instance via new XCrawl.
class XCrawl {
private readonly baseConfig
constructor(baseConfig?: IXCrawlBaseConifg)
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
}
```
Expand All @@ -67,6 +67,24 @@ const myXCrawl = new XCrawl({
})
```
### fetchHTML
fetchHTML is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, usually used to crawl HTML.
- Type
```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- Example

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```
### fetchData
fetchData is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, which is usually used to crawl APIs to obtain JSON data and so on.
Expand Down Expand Up @@ -123,24 +141,6 @@ myXCrawl.fetchFile({
})
```
### fetchHTML
fetchHTML is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, usually used to crawl HTML.
- Type
```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- Example

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```
## Types
- IAnyObject
Expand Down Expand Up @@ -220,6 +220,12 @@ interface IXCrawlBaseConifg {
}
```
- IFetchHTMLConfig
```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```
- IFetchDataConfig
```ts
Expand All @@ -237,12 +243,6 @@ interface IFetchFileConfig extends IFetchBaseConifg {
}
```
- IFetchHTMLConfig
```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```
## More
If you have any **questions** or **needs** , please submit **Issues in** https://github.com/coder-hxl/x-crawl/issues .
Expand Down Expand Up @@ -298,9 +298,9 @@ docsXCrawl.fetchHTML('/zh/get-started').then((jsdom) => {
class XCrawl {
private readonly baseConfig
constructor(baseConfig?: IXCrawlBaseConifg)
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
}
```

Expand Down Expand Up @@ -347,6 +347,24 @@ myXCrawl.fetchData({
})
```

### fetchHTML

fetchHTML 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取 HTML

- 类型

```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- 示例

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```

### fetchFile

fetchFile 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取文件,可获取图片、pdf 文件等等。
Expand Down Expand Up @@ -376,24 +394,6 @@ myXCrawl.fetchFile({
})
```

### fetchHTML

fetchHTML 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取 HTML

- 类型

```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- 示例

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```

## 类型

- IAnyObject
Expand Down Expand Up @@ -473,6 +473,12 @@ interface IXCrawlBaseConifg {
}
```

- IFetchHTMLConfig

```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```

- IFetchDataConfig

```ts
Expand All @@ -490,12 +496,6 @@ interface IFetchFileConfig extends IFetchBaseConifg {
}
```

- IFetchHTMLConfig

```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```

## 更多

如有 **问题****需求** 请在 https://github.com/coder-hxl/x-crawl/issues 中提 **Issues** 。
88 changes: 50 additions & 38 deletions publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Create a crawler instance via new XCrawl.
class XCrawl {
private readonly baseConfig
constructor(baseConfig?: IXCrawlBaseConifg)
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
fetchHTML(url: string): Promise<JSDOM>
}
```
Expand All @@ -67,6 +67,24 @@ const myXCrawl = new XCrawl({
})
```
### fetchHTML
fetchHTML is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, usually used to crawl HTML.
- Type
```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- Example

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```
### fetchData
fetchData is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, which is usually used to crawl APIs to obtain JSON data and so on.
Expand Down Expand Up @@ -123,24 +141,6 @@ myXCrawl.fetchFile({
})
```
### fetchHTML
fetchHTML is the method of the above <a href="#myXCrawl" style="text-decoration: none">myXCrawl</a> instance, usually used to crawl HTML.
- Type
```ts
function fetchHTML(url: string): Promise<JSDOM>
```

- Example

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```
## Types
- IAnyObject
Expand Down Expand Up @@ -220,6 +220,12 @@ interface IXCrawlBaseConifg {
}
```
- IFetchHTMLConfig
```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```
- IFetchDataConfig
```ts
Expand Down Expand Up @@ -292,9 +298,9 @@ docsXCrawl.fetchHTML('/zh/get-started').then((jsdom) => {
class XCrawl {
private readonly baseConfig
constructor(baseConfig?: IXCrawlBaseConifg)
fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
fetchHTML(url: string): Promise<JSDOM>
}
```

Expand Down Expand Up @@ -341,6 +347,24 @@ myXCrawl.fetchData({
})
```

### fetchHTML

fetchHTML 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取 HTML

- 类型

```ts
function fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM>
```

- 示例

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```

### fetchFile

fetchFile 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取文件,可获取图片、pdf 文件等等。
Expand Down Expand Up @@ -370,24 +394,6 @@ myXCrawl.fetchFile({
})
```

### fetchHTML

fetchHTML 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</a> 实例的方法,通常用于爬取 HTML

- 类型

```ts
function fetchHTML(url: string): Promise<JSDOM>
```

- 示例

```js
myXCrawl.fetchHTML('/xxx').then((jsdom) => {
console.log(jsdom.window.document.querySelector('title')?.textContent)
})
```

## 类型

- IAnyObject
Expand Down Expand Up @@ -467,6 +473,12 @@ interface IXCrawlBaseConifg {
}
```

- IFetchHTMLConfig

```ts
interface IFetchHTMLConfig extends IRequestConfig {}
```

- IFetchDataConfig

```ts
Expand Down
34 changes: 17 additions & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { isArray, isString, isUndefined } from './utils'

import {
IXCrawlBaseConifg,
IFetchHTMLConfig,
IFetchDataConfig,
IFetchFileConfig,
IFetchHTMLConfig,
IFetchBaseConifg,
IFileInfo,
IFetchCommon,
Expand Down Expand Up @@ -57,6 +57,22 @@ export default class XCrawl {
this.baseConfig = baseConfig
}

async fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM> {
const rawRequestConifg: IFetchHTMLConfig = isString(config)
? { url: config }
: config

const { requestConifg } = mergeConfig(this.baseConfig, {
requestConifg: rawRequestConifg
})

const requestResItem = await request(requestConifg)

const dom = new JSDOM(requestResItem.data)

return dom
}

async fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>> {
const { requestConifg, intervalTime } = mergeConfig(this.baseConfig, config)

Expand Down Expand Up @@ -145,20 +161,4 @@ export default class XCrawl {
batchRequest(requestConfigQueue, intervalTime, batchRequestResHandle)
})
}

async fetchHTML(config: string | IFetchHTMLConfig): Promise<JSDOM> {
const rawRequestConifg: IFetchHTMLConfig = isString(config)
? { url: config }
: config

const { requestConifg } = mergeConfig(this.baseConfig, {
requestConifg: rawRequestConifg
})

const requestResItem = await request(requestConifg)

const dom = new JSDOM(requestResItem.data)

return dom
}
}
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface IFetchBaseConifg {
intervalTime?: IIntervalTime
}

export interface IFetchHTMLConfig extends IRequestConfig {}

export interface IFetchDataConfig extends IFetchBaseConifg {}

export interface IFetchFileConfig extends IFetchBaseConifg {
Expand All @@ -74,8 +76,6 @@ export interface IFetchFileConfig extends IFetchBaseConifg {
}
}

export interface IFetchHTMLConfig extends IRequestConfig {}

export interface IFileInfo {
fileName: string
mimeType: string
Expand Down
Loading

0 comments on commit b2e9f07

Please sign in to comment.