Datasets:
[update]edist gitattributes
Browse files- .gitattributes +2 -0
- .gitignore +6 -0
- README.md +4 -1
- examples/parse_product.py +143 -0
- examples/range_spider.py +175 -0
- install.sh +62 -0
- project_settings.py +20 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
56 |
+
*.jsonl filter=lfs diff=lfs merge=lfs -text
|
57 |
+
*.json filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
.git/
|
3 |
+
.idea/
|
4 |
+
|
5 |
+
**/data/
|
6 |
+
**/__pycache__/
|
README.md
CHANGED
@@ -8,4 +8,7 @@ tags:
|
|
8 |
- e-commerce
|
9 |
size_categories:
|
10 |
- 1M<n<10M
|
11 |
-
---
|
|
|
|
|
|
|
|
8 |
- e-commerce
|
9 |
size_categories:
|
10 |
- 1M<n<10M
|
11 |
+
---
|
12 |
+
## 电商客户服务数据集
|
13 |
+
|
14 |
+
是从 (lightinthebox)[https://www.lightinthebox.com/] 网站收集的电商数据. 此数据可用于电商客服机器人的研究.
|
examples/parse_product.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import json
|
4 |
+
import re
|
5 |
+
import requests
|
6 |
+
from bs4 import BeautifulSoup
|
7 |
+
|
8 |
+
|
9 |
+
# url = "https://www.lightinthebox.com/en/p/_p9637820.html"
|
10 |
+
url = "https://www.lightinthebox.com/en/p/_p9528890.html"
|
11 |
+
|
12 |
+
resp = requests.get(url)
|
13 |
+
|
14 |
+
text = resp.text
|
15 |
+
|
16 |
+
print(resp.text)
|
17 |
+
|
18 |
+
|
19 |
+
pattern_without_rating = r"""
|
20 |
+
name":"(.*)","image":\[(?:.*)\],"brand":"(.*)","review":"(.*)","description":"(.*)","mpn":"(.*)","color":"(.*)","size":"(.*)","sku":"(.*?)".*,"offers":{"@type":"Offer","availability":"(?:.*)","priceCurrency":"(.*)","price":"(.*)","priceValidUntil":"(.*)","url
|
21 |
+
"""
|
22 |
+
pattern_without_rating = str(pattern_without_rating).strip()
|
23 |
+
|
24 |
+
pattern_review = r"""
|
25 |
+
aggregateRating":(?:.*)ratingValue":"(.*)","reviewCount":"(.*)"},"offers
|
26 |
+
"""
|
27 |
+
pattern_review = str(pattern_review).strip()
|
28 |
+
|
29 |
+
pattern_description = r"""
|
30 |
+
<div class="des-title-div">.*<h2 class="des-title">
|
31 |
+
"""
|
32 |
+
pattern_description = str(pattern_description).strip()
|
33 |
+
|
34 |
+
|
35 |
+
match = re.search(pattern_without_rating, text, flags=re.IGNORECASE)
|
36 |
+
title = match.group(1)
|
37 |
+
brand = match.group(2)
|
38 |
+
review = match.group(3)
|
39 |
+
description = match.group(4)
|
40 |
+
mpn = match.group(5)
|
41 |
+
# color = match.group(6)
|
42 |
+
# size = match.group(7)
|
43 |
+
sku = match.group(8)
|
44 |
+
priceCurrency = match.group(9)
|
45 |
+
price = match.group(10)
|
46 |
+
priceValidUntil = match.group(11)
|
47 |
+
|
48 |
+
|
49 |
+
match = re.search(pattern_review, text, flags=re.IGNORECASE)
|
50 |
+
if match is not None:
|
51 |
+
ratingValue = match.group(1)
|
52 |
+
reviewCount = match.group(2)
|
53 |
+
else:
|
54 |
+
ratingValue = None
|
55 |
+
reviewCount = None
|
56 |
+
|
57 |
+
|
58 |
+
soup = BeautifulSoup(text, features="html.parser")
|
59 |
+
|
60 |
+
matches = soup.find_all(class_="description-item")
|
61 |
+
result = list()
|
62 |
+
for match in matches:
|
63 |
+
match_text = match.text.strip()
|
64 |
+
match_text = str(match_text).strip().split("\n")
|
65 |
+
for row in match_text:
|
66 |
+
row = str(row).strip()
|
67 |
+
if len(row) == 0:
|
68 |
+
continue
|
69 |
+
if row in ("Size Chart", "Photos"):
|
70 |
+
break
|
71 |
+
result.append(row)
|
72 |
+
overview = "\n".join(result)
|
73 |
+
|
74 |
+
|
75 |
+
matches = soup.find_all(class_="breadcrumbAB")
|
76 |
+
result = list()
|
77 |
+
for match in matches:
|
78 |
+
match_text = match.text.strip()
|
79 |
+
match_text = str(match_text).strip().split("\n")
|
80 |
+
for row in match_text:
|
81 |
+
row = str(row).strip()
|
82 |
+
if len(row) == 0:
|
83 |
+
continue
|
84 |
+
result.append(row)
|
85 |
+
category = "".join(result)
|
86 |
+
category = " > ".join(category.split(">"))
|
87 |
+
|
88 |
+
|
89 |
+
match_select_color = soup.find("select", class_="select-color-show")
|
90 |
+
matches = match_select_color.find_all("option")
|
91 |
+
color = list()
|
92 |
+
for match in matches:
|
93 |
+
match_text = match.text.strip()
|
94 |
+
if match_text == "Color":
|
95 |
+
continue
|
96 |
+
color.append(match_text)
|
97 |
+
|
98 |
+
|
99 |
+
match_selects = soup.find_all("select", class_="attr-list-select")
|
100 |
+
color_size = [[], []]
|
101 |
+
color_size_idx = None
|
102 |
+
for match_select in match_selects:
|
103 |
+
matches = match_select.find_all("option")
|
104 |
+
for idx, match in enumerate(matches):
|
105 |
+
match_text = match.text.strip()
|
106 |
+
|
107 |
+
if idx == 0:
|
108 |
+
if match_text == "Color":
|
109 |
+
color_size_idx = 0
|
110 |
+
elif match_text == "Size":
|
111 |
+
color_size_idx = 1
|
112 |
+
else:
|
113 |
+
break
|
114 |
+
continue
|
115 |
+
|
116 |
+
color_size[color_size_idx].append(match_text)
|
117 |
+
|
118 |
+
color = color_size[0]
|
119 |
+
size = color_size[1]
|
120 |
+
|
121 |
+
|
122 |
+
row = {
|
123 |
+
"title": title,
|
124 |
+
"brand": brand,
|
125 |
+
"review": str(review).strip() if len(str(review).strip()) != 0 else None,
|
126 |
+
"description": description,
|
127 |
+
"mpn": mpn,
|
128 |
+
"color": color,
|
129 |
+
"size": size,
|
130 |
+
"sku": sku,
|
131 |
+
"ratingValue": ratingValue,
|
132 |
+
"reviewCount": reviewCount,
|
133 |
+
"overview": overview,
|
134 |
+
"category": category,
|
135 |
+
"url": "https://www.lightinthebox.com/en/p/_p{}.html".format(mpn)
|
136 |
+
|
137 |
+
}
|
138 |
+
row = json.dumps(row, indent=4, ensure_ascii=False)
|
139 |
+
print(row)
|
140 |
+
|
141 |
+
|
142 |
+
if __name__ == '__main__':
|
143 |
+
pass
|
examples/range_spider.py
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import json
|
4 |
+
import random
|
5 |
+
import re
|
6 |
+
import time
|
7 |
+
|
8 |
+
import requests
|
9 |
+
from bs4 import BeautifulSoup
|
10 |
+
from tqdm import tqdm
|
11 |
+
|
12 |
+
|
13 |
+
pattern_without_rating = r"""
|
14 |
+
name":"(.*)","image":\[(?:.*)\],"brand":"(.*)","review":"(.*)","description":"(.*)","mpn":"(.*)","color":"(.*)","size":"(.*)","sku":"(.*?)".*,"offers":{"@type":"Offer","availability":"(?:.*)","priceCurrency":"(.*)","price":"(.*)","priceValidUntil":"(.*)","url
|
15 |
+
"""
|
16 |
+
pattern_without_rating = str(pattern_without_rating).strip()
|
17 |
+
|
18 |
+
pattern_review = r"""
|
19 |
+
aggregateRating":(?:.*)ratingValue":"(.*)","reviewCount":"(.*)"},"offers
|
20 |
+
"""
|
21 |
+
pattern_review = str(pattern_review).strip()
|
22 |
+
|
23 |
+
pattern_description = r"""
|
24 |
+
<div class="des-title-div">.*<h2 class="des-title">
|
25 |
+
"""
|
26 |
+
pattern_description = str(pattern_description).strip()
|
27 |
+
|
28 |
+
|
29 |
+
def parse_text(text: str):
|
30 |
+
match = re.search(pattern_without_rating, text, flags=re.IGNORECASE)
|
31 |
+
title = match.group(1)
|
32 |
+
brand = match.group(2)
|
33 |
+
review = match.group(3)
|
34 |
+
description = match.group(4)
|
35 |
+
mpn = match.group(5)
|
36 |
+
sku = match.group(8)
|
37 |
+
price = match.group(10)
|
38 |
+
|
39 |
+
match = re.search(pattern_review, text, flags=re.IGNORECASE)
|
40 |
+
if match is not None:
|
41 |
+
rating_value = match.group(1)
|
42 |
+
review_count = match.group(2)
|
43 |
+
else:
|
44 |
+
rating_value = None
|
45 |
+
review_count = None
|
46 |
+
|
47 |
+
soup = BeautifulSoup(text, features="html.parser")
|
48 |
+
|
49 |
+
matches = soup.find_all(class_="description-item")
|
50 |
+
result = list()
|
51 |
+
for match in matches:
|
52 |
+
match_text = match.text.strip()
|
53 |
+
match_text = str(match_text).strip().split("\n")
|
54 |
+
for row in match_text:
|
55 |
+
row = str(row).strip()
|
56 |
+
if len(row) == 0:
|
57 |
+
continue
|
58 |
+
if row in ("Size Chart", "Photos"):
|
59 |
+
break
|
60 |
+
result.append(row)
|
61 |
+
overview = "\n".join(result)
|
62 |
+
|
63 |
+
matches = soup.find_all(class_="breadcrumbAB")
|
64 |
+
result = list()
|
65 |
+
for match in matches:
|
66 |
+
match_text = match.text.strip()
|
67 |
+
match_text = str(match_text).strip().split("\n")
|
68 |
+
for row in match_text:
|
69 |
+
row = str(row).strip()
|
70 |
+
if len(row) == 0:
|
71 |
+
continue
|
72 |
+
result.append(row)
|
73 |
+
category = "".join(result)
|
74 |
+
category = " > ".join(category.split(">"))
|
75 |
+
|
76 |
+
match_select_color = soup.find("select", class_="select-color-show")
|
77 |
+
matches = match_select_color.find_all("option")
|
78 |
+
color = list()
|
79 |
+
for match in matches:
|
80 |
+
match_text = match.text.strip()
|
81 |
+
if match_text == "Color":
|
82 |
+
continue
|
83 |
+
color.append(match_text)
|
84 |
+
|
85 |
+
match_selects = soup.find_all("select", class_="attr-list-select")
|
86 |
+
color_size = [[], []]
|
87 |
+
color_size_idx = None
|
88 |
+
for match_select in match_selects:
|
89 |
+
matches = match_select.find_all("option")
|
90 |
+
for idx, match in enumerate(matches):
|
91 |
+
match_text = match.text.strip()
|
92 |
+
|
93 |
+
if idx == 0:
|
94 |
+
if match_text == "Color":
|
95 |
+
color_size_idx = 0
|
96 |
+
elif match_text == "Size":
|
97 |
+
color_size_idx = 1
|
98 |
+
else:
|
99 |
+
break
|
100 |
+
continue
|
101 |
+
|
102 |
+
color_size[color_size_idx].append(match_text)
|
103 |
+
|
104 |
+
color = color_size[0]
|
105 |
+
size = color_size[1]
|
106 |
+
|
107 |
+
row = {
|
108 |
+
"title": title,
|
109 |
+
"brand": brand,
|
110 |
+
"review": str(review).strip() if len(str(review).strip()) != 0 else None,
|
111 |
+
"description": description,
|
112 |
+
"mpn": mpn,
|
113 |
+
"color": color,
|
114 |
+
"size": size,
|
115 |
+
"sku": sku,
|
116 |
+
"ratingValue": rating_value,
|
117 |
+
"reviewCount": review_count,
|
118 |
+
"overview": overview,
|
119 |
+
"category": category,
|
120 |
+
"url": "https://www.lightinthebox.com/en/p/_p{}.html".format(mpn)
|
121 |
+
}
|
122 |
+
return row
|
123 |
+
|
124 |
+
|
125 |
+
headers = {
|
126 |
+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
127 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
|
128 |
+
}
|
129 |
+
|
130 |
+
finished_mpn = set()
|
131 |
+
|
132 |
+
output_file = "product.jsonl"
|
133 |
+
with open(output_file, "r", encoding="utf-8") as f:
|
134 |
+
for row in f:
|
135 |
+
row = str(row).strip()
|
136 |
+
row = json.loads(row)
|
137 |
+
mpn = row["mpn"]
|
138 |
+
finished_mpn.add(mpn)
|
139 |
+
|
140 |
+
print("finished count: {}".format(len(finished_mpn)))
|
141 |
+
|
142 |
+
sleep_time = 1
|
143 |
+
for mpn in tqdm(range(9156603, 9999999)):
|
144 |
+
# mpn = random.randint(9000000, 9999999)
|
145 |
+
if mpn in finished_mpn:
|
146 |
+
continue
|
147 |
+
finished_mpn.add(mpn)
|
148 |
+
|
149 |
+
url = "https://www.lightinthebox.com/en/p/_p{}.html".format(mpn)
|
150 |
+
print("url: {}".format(url))
|
151 |
+
|
152 |
+
try:
|
153 |
+
resp = requests.get(url, headers=headers, timeout=2)
|
154 |
+
except Exception:
|
155 |
+
print("sleep: {}".format(sleep_time))
|
156 |
+
time.sleep(sleep_time)
|
157 |
+
sleep_time += 1
|
158 |
+
continue
|
159 |
+
|
160 |
+
text = resp.text
|
161 |
+
try:
|
162 |
+
row = parse_text(text)
|
163 |
+
except Exception:
|
164 |
+
continue
|
165 |
+
|
166 |
+
sleep_time = 1
|
167 |
+
row = json.dumps(row, ensure_ascii=False)
|
168 |
+
with open(output_file, "a+", encoding="utf-8") as f:
|
169 |
+
f.write("{}\n".format(row))
|
170 |
+
f.flush()
|
171 |
+
print(row)
|
172 |
+
|
173 |
+
|
174 |
+
if __name__ == '__main__':
|
175 |
+
pass
|
install.sh
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env bash
|
2 |
+
|
3 |
+
# sh install.sh --stage -1 --stop_stage -1 --system_version windows
|
4 |
+
# sh install.sh --stage -1 --stop_stage -1 --system_version centos
|
5 |
+
# sh install.sh --stage 1 --stop_stage 1 --system_version centos
|
6 |
+
|
7 |
+
python_version=3.8.10
|
8 |
+
system_version=centos
|
9 |
+
|
10 |
+
verbose=true;
|
11 |
+
stage=-1
|
12 |
+
stop_stage=3
|
13 |
+
|
14 |
+
work_dir="$(pwd)"
|
15 |
+
|
16 |
+
# parse options
|
17 |
+
while true; do
|
18 |
+
[ -z "${1:-}" ] && break; # break if there are no arguments
|
19 |
+
case "$1" in
|
20 |
+
--*) name=$(echo "$1" | sed s/^--// | sed s/-/_/g);
|
21 |
+
eval '[ -z "${'"$name"'+xxx}" ]' && echo "$0: invalid option $1" 1>&2 && exit 1;
|
22 |
+
old_value="(eval echo \\$$name)";
|
23 |
+
if [ "${old_value}" == "true" ] || [ "${old_value}" == "false" ]; then
|
24 |
+
was_bool=true;
|
25 |
+
else
|
26 |
+
was_bool=false;
|
27 |
+
fi
|
28 |
+
|
29 |
+
# Set the variable to the right value-- the escaped quotes make it work if
|
30 |
+
# the option had spaces, like --cmd "queue.pl -sync y"
|
31 |
+
eval "${name}=\"$2\"";
|
32 |
+
|
33 |
+
# Check that Boolean-valued arguments are really Boolean.
|
34 |
+
if $was_bool && [[ "$2" != "true" && "$2" != "false" ]]; then
|
35 |
+
echo "$0: expected \"true\" or \"false\": $1 $2" 1>&2
|
36 |
+
exit 1;
|
37 |
+
fi
|
38 |
+
shift 2;
|
39 |
+
;;
|
40 |
+
|
41 |
+
*) break;
|
42 |
+
esac
|
43 |
+
done
|
44 |
+
|
45 |
+
|
46 |
+
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
|
47 |
+
$verbose && echo "stage 0: install python"
|
48 |
+
cd "${work_dir}" || exit 1;
|
49 |
+
|
50 |
+
sh ./script/install_python.sh --python_version "${python_version}" --system_version "${system_version}"
|
51 |
+
fi
|
52 |
+
|
53 |
+
|
54 |
+
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
|
55 |
+
$verbose && echo "stage 1: create virtualenv"
|
56 |
+
/usr/local/python-${python_version}/bin/pip3 install virtualenv
|
57 |
+
mkdir -p /data/local/bin
|
58 |
+
cd /data/local/bin || exit 1;
|
59 |
+
# source /data/local/bin/e_commerce_customer_service/bin/activate
|
60 |
+
/usr/local/python-${python_version}/bin/virtualenv e_commerce_customer_service
|
61 |
+
|
62 |
+
fi
|
project_settings.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/python3
|
2 |
+
# -*- coding: utf-8 -*-
|
3 |
+
import os
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
from toolbox.os.environment import EnvironmentManager
|
7 |
+
|
8 |
+
|
9 |
+
project_path = os.path.abspath(os.path.dirname(__file__))
|
10 |
+
project_path = Path(project_path)
|
11 |
+
|
12 |
+
|
13 |
+
environment = EnvironmentManager(
|
14 |
+
path=os.path.join(project_path, 'dotenv'),
|
15 |
+
env=os.environ.get('environment', 'dev'),
|
16 |
+
)
|
17 |
+
|
18 |
+
|
19 |
+
if __name__ == '__main__':
|
20 |
+
pass
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
beautifulsoup4==4.12.2
|
2 |
+
requests==2.31.0
|
3 |
+
tqdm==4.65.0
|