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
ca8b590a
authored
Apr 29, 2019
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add x912688
parent
2f3c1618
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
plat/x912688/cate_stock.py
plat/x912688/cate_stock.py
View file @
ca8b590a
from
utils.base
import
Module_Base
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"
,
}
...
...
@@ -6,27 +7,38 @@ a = Module_Base()
url
=
'http://www.912688.com/'
resp
=
a
.
requests
.
get
(
url
,
headers
=
headers
)
resp
.
encoding
=
'utf-8'
resp
=
resp
.
text
resp
=
resp
.
text
dom
=
a
.
etree
.
HTML
(
resp
)
level1_doms
=
dom
.
xpath
(
'//div[@id="kx_allsort"]/div//dl'
)
levels
=
[]
for
level1_dom
in
level1_doms
:
level1
=
dict
()
level1
[
'cat_name'
]
=
level1_dom
.
xpath
(
'.//h2/text()'
)[
0
]
level1
[
'url'
]
=
''
level1
[
'level'
]
=
1
level1
[
'islast'
]
=
0
level1
[
'parent_id'
]
=
0
level1
[
'level2_list'
]
=
[]
# print('一级分类',level1)
level2_doms
=
level1_dom
.
xpath
(
'.//dd/a'
)
level1_doms
=
dom
.
xpath
(
'//div[@class="fore7"]//dl[@class="no-border"]//dd//a'
)
def
get_resps
(
level1
):
text
=
a
.
requests
.
get
(
level1
[
'url'
],
headers
=
headers
)
.
text
dom
=
a
.
etree
.
HTML
(
text
)
level2_doms
=
dom
.
xpath
(
'//div[@class="list_layout_filter"]//li/a'
)
for
level2_dom
in
level2_doms
:
level2
=
{}
level2
[
'cat_name'
]
=
level2_dom
.
xpath
(
'./
text()
'
)[
0
]
level2
[
'cat_name'
]
=
level2_dom
.
xpath
(
'./
@title
'
)[
0
]
level2
[
'url'
]
=
level2_dom
.
xpath
(
'./@href'
)[
0
]
level2
[
'level'
]
=
2
level2
[
'islast'
]
=
1
level1
[
'level2_list'
]
.
append
(
level2
)
# print('二级分类',level2)
levels
.
append
(
level1
)
# print('二级分类', level2)
return
level1
def
get_levels
():
levels
=
[]
for
level1_dom
in
level1_doms
:
level1
=
dict
()
level1
[
'cat_name'
]
=
level1_dom
.
xpath
(
'./text()'
)[
0
]
level1
[
'url'
]
=
level1_dom
.
xpath
(
'./@href'
)[
0
]
level1
[
'level'
]
=
1
level1
[
'islast'
]
=
0
level1
[
'parent_id'
]
=
0
level1
[
'level2_list'
]
=
[]
# print('一级分类',level1)
level1_ok
=
get_resps
(
level1
)
levels
.
append
(
level1_ok
)
return
levels
levels
=
get_levels
()
print
(
levels
)
\ No newline at end of file
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