Skip to content

Commit a6c44b8

Browse files
committed
FIX: conflict
2 parents 1aa635a + 921f18a commit a6c44b8

30 files changed

+596
-229
lines changed

data/driver.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import sqlite3
2+
from contextlib import closing
3+
from lib.logger import logger
4+
import time
25

36
class SqliteStore:
47
def __init__(self, db_path):
@@ -8,3 +11,74 @@ def _get_connection(self):
811
conn = sqlite3.connect(self.db_path)
912
conn.row_factory = sqlite3.Row # 结果以字典形式返回
1013
return conn
14+
15+
class CommonAccount(SqliteStore):
16+
def __init__(self, store_path, pool_size=5):
17+
super().__init__(store_path, pool_size)
18+
self.primary_key = 'id'
19+
self.table_name = 'account'
20+
self._create_table()
21+
22+
def _create_table(self):
23+
with closing(self._get_connection()) as conn, closing(conn.cursor()) as cursor:
24+
try:
25+
sql = f'''
26+
CREATE TABLE IF NOT EXISTS {self.table_name} (
27+
{self.primary_key} VARCHAR(2048) PRIMARY KEY NOT NULL,
28+
cookie VARCHAR(2048) NOT NULL,
29+
expired INTEGER NOT NULL,
30+
ct INTEGER NOT NULL,
31+
ut INTEGER NOT NULL
32+
)
33+
'''
34+
cursor.execute(sql)
35+
conn.commit()
36+
except Exception as e:
37+
logger.error(f'failed to create table, error: {e}')
38+
39+
def save(self, id: str, cookie: str, expired: int) -> bool:
40+
ct = ut = int(time.time())
41+
with closing(self._get_connection()) as conn, closing(conn.cursor()) as cursor:
42+
try:
43+
sql = f'UPDATE {self.table_name} SET cookie = ?, expired = ?, ut = ? WHERE id = ?'
44+
cursor.execute(sql, (cookie, expired, ut, id))
45+
if cursor.rowcount == 0:
46+
sql = f'INSERT INTO {self.table_name} (cookie, expired, ct, ut, id) VALUES (?, ?, ?, ?, ?)'
47+
cursor.execute(sql, (cookie, expired, ct, ut, id))
48+
conn.commit()
49+
return True
50+
except Exception as e:
51+
logger.error(f'failed to save cookies, error: {e}')
52+
conn.rollback()
53+
return False
54+
55+
56+
def load(self, offset: int = 0, limit: int = 0) -> list:
57+
with closing(self._get_connection()) as conn, closing(conn.cursor()) as cursor:
58+
try:
59+
if limit == 0:
60+
sql = f'SELECT * FROM {self.table_name}'
61+
cursor.execute(sql)
62+
else:
63+
sql = f'SELECT * FROM {self.table_name} LIMIT ? OFFSET ?'
64+
cursor.execute(sql, (limit, offset))
65+
results = cursor.fetchall()
66+
return [dict(row) for row in results]
67+
except Exception as e:
68+
logger.error(f'failed to load cookies, error: {e}')
69+
conn.rollback()
70+
return []
71+
72+
def expire(self, id: str) -> bool:
73+
ut = int(time.time())
74+
with closing(self._get_connection()) as conn, closing(conn.cursor()) as cursor:
75+
try:
76+
sql = f'UPDATE {self.table_name} SET expired = ?, ut = ? WHERE id = ?'
77+
cursor.execute(sql, (1, ut, id))
78+
conn.commit()
79+
return True
80+
except Exception as e:
81+
logger.error(f'failed to save cookies, error: {e}')
82+
conn.rollback()
83+
return False
84+

data/jd/.gitkeep

Whitespace-only changes.

data/taobao/.gitkeep

Whitespace-only changes.

docs/api/jd/jd.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# API 文档
2+
3+
## 京东
4+
5+
### 添加账号
6+
7+
- **功能说明**
8+
9+
用于添加京东账号。
10+
11+
- **URL**
12+
13+
`/jd/add_account`
14+
15+
- **Method**
16+
17+
`POST`
18+
19+
- **Data Params**
20+
21+
| 参数 | 必选 | 类型 | 说明 |
22+
|:---:|:---:|:---:|:---:|
23+
| id | true | string | 账户名(用于管理用户cookie) |
24+
| cookie | true | string | 京东cookie |
25+
26+
- **Response**
27+
28+
| 参数 | 必选 | 类型 | 说明 |
29+
|:---:|:---:|:---:|:---:|
30+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
31+
| data | true | struct | 数据 |
32+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
33+
34+
### 获取账号列表
35+
36+
- **URL**
37+
38+
`/jd/account_list`
39+
40+
- **Method**
41+
42+
`GET`
43+
44+
- **URL Params**
45+
46+
None
47+
48+
- **Response**
49+
50+
| 参数 | 必选 | 类型 | 说明 |
51+
|:---:|:---:|:---:|:---:|
52+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
53+
| data | true | list | [ [账户信息](#账户信息) ] |
54+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
55+
56+
#### 账户信息
57+
58+
| 参数 | 必选 | 类型 | 说明 |
59+
|:---:|:---:|:---:|:---:|
60+
| id | true | string | 账户名(用于管理用户cookie) |
61+
| cookie | true | string | 京东cookie |
62+
| ct | true | int | 创建时间戳 |
63+
| ut | true | int | 更新时间戳 |
64+
| expired | true | int | 0: 有效 1: 过期 (请求失败时自动设为过期) |
65+
66+
### 关键词搜索商品
67+
68+
- **URL**
69+
70+
`/jd/search`
71+
72+
- **Method**
73+
74+
`GET`
75+
76+
- **URL Params**
77+
78+
| 参数 | 必选 | 类型 | 说明 |
79+
|:---:|:---:|:---:|:---:|
80+
| keyword | true | string | 搜索词 |
81+
| offset | false | int | 搜索翻页偏移量, 默认0 |
82+
| limit | false | int | 结果数量, 默认30 |
83+
84+
- **Success Response**
85+
86+
| 参数 | 必选 | 类型 | 说明 |
87+
|:---:|:---:|:---:|:---:|
88+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
89+
| data | true | struct | 数据 |
90+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
91+

docs/api/taobao/taobao.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# API 文档
2+
3+
## 淘宝
4+
5+
### 添加账号
6+
7+
- **功能说明**
8+
9+
用于添加淘宝账号。
10+
11+
- **URL**
12+
13+
`/taobao/add_account`
14+
15+
- **Method**
16+
17+
`POST`
18+
19+
- **Data Params**
20+
21+
| 参数 | 必选 | 类型 | 说明 |
22+
|:---:|:---:|:---:|:---:|
23+
| id | true | string | 账户名(用于管理用户cookie) |
24+
| cookie | true | string | 淘宝cookie |
25+
26+
- **Response**
27+
28+
| 参数 | 必选 | 类型 | 说明 |
29+
|:---:|:---:|:---:|:---:|
30+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
31+
| data | true | struct | 数据 |
32+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
33+
34+
### 获取账号列表
35+
36+
- **URL**
37+
38+
`/taobao/account_list`
39+
40+
- **Method**
41+
42+
`GET`
43+
44+
- **URL Params**
45+
46+
None
47+
48+
- **Response**
49+
50+
| 参数 | 必选 | 类型 | 说明 |
51+
|:---:|:---:|:---:|:---:|
52+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
53+
| data | true | list | [ [账户信息](#账户信息) ] |
54+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
55+
56+
#### 账户信息
57+
58+
| 参数 | 必选 | 类型 | 说明 |
59+
|:---:|:---:|:---:|:---:|
60+
| id | true | string | 账户名(用于管理用户cookie) |
61+
| cookie | true | string | 淘宝cookie |
62+
| ct | true | int | 创建时间戳 |
63+
| ut | true | int | 更新时间戳 |
64+
| expired | true | int | 0: 有效 1: 过期 (请求失败时自动设为过期) |
65+
66+
### 关键词搜索商品
67+
68+
- **URL**
69+
70+
`/taobao/search`
71+
72+
- **Method**
73+
74+
`GET`
75+
76+
- **URL Params**
77+
78+
| 参数 | 必选 | 类型 | 说明 |
79+
|:---:|:---:|:---:|:---:|
80+
| keyword | true | string | 搜索词 |
81+
| offset | false | int | 搜索翻页偏移量, 默认0 |
82+
| limit | false | int | 结果数量, 默认48 |
83+
84+
- **Success Response**
85+
86+
| 参数 | 必选 | 类型 | 说明 |
87+
|:---:|:---:|:---:|:---:|
88+
| code | true | int | 0: 成功 1: 参数错误 2: 服务器错误 |
89+
| data | true | struct | 数据 |
90+
| msg | true | string | 请求说明(成功、参数错误、服务器错误) |
91+

docs/doc.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,23 @@
5151
- 小红书搜索结果获取
5252

5353
小红书:[API 文档](api/xhs/xhs.md)
54+
55+
## 淘宝
56+
57+
目前支持以下接口:
58+
59+
- 添加淘宝账号
60+
- 获取淘宝账号列表
61+
- 淘宝搜索结果获取
62+
63+
淘宝:[API 文档](api/taobao/taobao.md)
64+
65+
## 京东
66+
67+
目前支持以下接口:
68+
69+
- 添加京东账号
70+
- 获取京东账号列表
71+
- 京东搜索结果获取
72+
73+
京东:[API 文档](api/jd/jd.md)

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from service.kuaishou.urls import kuaishou
44
from service.bilibili.urls import bilibili
55
from service.xhs.urls import xhs
6+
from service.taobao.urls import taobao
7+
from service.jd.urls import jd
68
from lib.logger import logger
79
import yaml
810

@@ -11,6 +13,8 @@
1113
app.register_blueprint(kuaishou, url_prefix="/kuaishou")
1214
app.register_blueprint(bilibili, url_prefix="/bilibili")
1315
app.register_blueprint(xhs, url_prefix="/xhs")
16+
app.register_blueprint(taobao, url_prefix="/taobao")
17+
app.register_blueprint(jd, url_prefix="/jd")
1418

1519
def init_service():
1620
config_file = "config/config.yaml"

readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# 服务 - 主流媒体平台爬虫
22

3-
抖音、快手、哔哩哔哩、小红书平台爬虫服务器项目。它可以获取这些平台上的公开信息,但请遵守下方的的免责声明。
3+
抖音、快手、哔哩哔哩、小红书、淘宝、京东平台爬虫服务器项目。它可以获取这些平台上的公开信息,但请遵守下方的的免责声明。
44

55
## 免责声明
66

77
本项目的初衷是为了帮助开发者更好地了解和掌握这些平台,也希望能帮助企业和安全工程师了解爬虫手段,提高平台的反爬虫措施,而不是用于非法用途,反对用于任何违反相关法律法规的行为。
88

99
仅供学习和研究使用,不得用于任何商业用途或非法目的。使用本项目提供的功能时,用户需自行承担可能带来的一切法律责任。
1010

11-
我们提供的爬虫仅能获取抖音,快手、哔哩哔哩、小红书等平台上公开的信息,我们强烈反对任何形式的隐私侵犯行为。如果你使用本项目进行了侵犯他人隐私的行为,我们将与你保持距离,并支持受害者通过法律手段维护自己的权益。
11+
我们提供的爬虫仅能获取抖音,快手、哔哩哔哩、小红书、淘宝、京东等平台上公开的信息,我们强烈反对任何形式的隐私侵犯行为。如果你使用本项目进行了侵犯他人隐私的行为,我们将与你保持距离,并支持受害者通过法律手段维护自己的权益。
1212

1313
使用本仓库的内容即表示您同意本免责声明的所有条款和条件。如果你不接受以上的免责声明,请立即停止使用本项目。
1414

@@ -18,7 +18,7 @@
1818

1919
## 功能
2020

21-
- 快手、抖音、哔哩哔哩、小红书平台的爬虫接口
21+
- 快手、抖音、哔哩哔哩、小红书、淘宝、京东平台的爬虫接口
2222
- 获取公开的用户信息,帖子信息等
2323
- 使用简单,支持多种语言使用HTTP调用
2424
- 哔哩哔哩视频[一键下载](docs/api/bilibili/bilibili.md#bilibili视频下载)
@@ -73,7 +73,7 @@
7373
cat .log/crawler.log # access.log error.log
7474
```
7575

76-
首次使用需添加账号,例如:调用`http://localhost:8080/{platfrom}/add_account`添加账号,platfrom取`douyin``kuaishou``bilibili``xhs`,接口详情请参考[API 文档](docs/doc.md)。
76+
首次使用需添加账号,例如:调用`http://localhost:8080/{platfrom}/add_account`添加账号,platfrom取`douyin``kuaishou``bilibili``xhs``taobao``jd`,接口详情请参考[API 文档](docs/doc.md)。
7777

7878
然后在你的代码中调用API,获取公开的信息。
7979

0 commit comments

Comments
 (0)