Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
lichenggang
/
update_cate
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
263fcee5
authored
May 08, 2019
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add testmart
parent
9157c712
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
plat/testmart/__init__.py
plat/testmart/cate_stock.py
plat/testmart/__init__.py
0 → 100644
View file @
263fcee5
File mode changed
plat/testmart/cate_stock.py
0 → 100644
View file @
263fcee5
from
utils.base
import
Module_Base
import
re
dom_pat
=
re
.
compile
(
r'\<script\>document\.write\(\"(.+)\"\)'
)
domain
=
'http:'
headers
=
{
"User-Agent"
:
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
,
}
a
=
Module_Base
()
url1
=
'https://www.testmart.cn/productlist/sortpage/cat/111.html'
url2
=
'https://www.testmart.cn/productlist/sortpage/cat/112.html'
resp1
=
a
.
requests
.
get
(
url1
,
headers
=
headers
)
.
text
resp2
=
a
.
requests
.
get
(
url2
,
headers
=
headers
)
.
text
dom1
=
a
.
etree
.
HTML
(
resp1
)
dom2
=
a
.
etree
.
HTML
(
resp2
)
level1_doms_1_1
=
dom1
.
xpath
(
'//div[@class="left-content"]//p'
)
level1_doms_1_2
=
dom1
.
xpath
(
'//div[@class="left-content"]//ul[@class="clearfix mb"]'
)
level1_doms_2_1
=
dom2
.
xpath
(
'//div[@class="left-content"]//p'
)
level1_doms_2_2
=
dom2
.
xpath
(
'//div[@class="left-content"]//ul[@class="clearfix mb"]'
)
level1_doms_1
=
zip
(
level1_doms_1_1
,
level1_doms_1_2
)
level1_doms_2
=
zip
(
level1_doms_2_1
,
level1_doms_2_2
)
def
get_levels
(
level1_doms
):
levels
=
[]
for
level1_dom
in
level1_doms
:
level1
=
dict
()
level1
[
'cat_name'
]
=
level1_dom
[
0
]
.
xpath
(
'.//a[1]/text()'
)[
0
]
.
strip
()
level1
[
'url'
]
=
level1_dom
[
0
]
.
xpath
(
'.//a[1]/@href'
)[
0
]
level1
[
'level'
]
=
1
level1
[
'islast'
]
=
0
level1
[
'parent_id'
]
=
0
level1
[
'level2_list'
]
=
[]
# print('一级分类',level1)
for
level2_dom
in
level1_dom
[
1
]
.
xpath
(
'.//a'
):
level2
=
{}
level2
[
'cat_name'
]
=
level2_dom
.
xpath
(
'./text()'
)[
0
]
.
strip
()
level2
[
'url'
]
=
level2_dom
.
xpath
(
'./@href'
)[
0
]
level2
[
'level'
]
=
2
level2
[
'islast'
]
=
1
level1
[
'level2_list'
]
.
append
(
level2
)
levels
.
append
(
level1
)
return
levels
levels1
=
get_levels
(
level1_doms_1
)
levels2
=
get_levels
(
level1_doms_2
)
# print(levels1)
# print(levels2)
levels
=
levels1
+
levels2
print
(
levels
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment