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
ea9a3d1c
authored
Apr 16, 2019
by
lichenggang
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
add huangye88
parent
6f297b1a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
6 deletions
plat/huangye88/__init__.py
plat/huangye88/cate_stock.py
update_scrip.py
updateopera.py
utils/mysqlopera.py
plat/huangye88/__init__.py
0 → 100644
View file @
ea9a3d1c
File mode changed
plat/huangye88/cate_stock.py
0 → 100644
View file @
ea9a3d1c
from
utils.base
import
Module_Base
kw_base
=
'https://s.hc360.com/seller/search.html?a=1&w={}'
headers
=
{
"Upgrade-Insecure-Requests"
:
"1"
,
"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
()
url
=
'http://yiqiyibiao.huangye88.com/'
resp
=
a
.
requests
.
get
(
url
,
headers
=
headers
)
.
text
dom
=
a
.
etree
.
HTML
(
resp
)
level1_name_doms
=
dom
.
xpath
(
'//ul[@class="cemenu"]//li[@class="s1 indent"]'
)
level1_content_doms
=
dom
.
xpath
(
'//div[@class="cetcont"]/div'
)
level1_doms
=
zip
(
level1_name_doms
,
level1_content_doms
)
levels
=
[]
for
level1_dom
in
level1_doms
:
level1
=
dict
()
level1
[
'cat_name'
]
=
level1_dom
[
0
]
.
xpath
(
'.//a/text()'
)[
0
]
level1
[
'url'
]
=
level1_dom
[
0
]
.
xpath
(
'.//a/@href'
)[
0
]
level1
[
'level'
]
=
1
level1
[
'islast'
]
=
0
level1
[
'parent_id'
]
=
0
level1
[
'level2_list'
]
=
[]
# print('一级分类',level1)
level2_doms
=
level1_dom
[
1
]
.
xpath
(
'.//div[@class="cilei"]//a'
)
for
level2_dom
in
level2_doms
:
level2
=
{}
level2
[
'cat_name'
]
=
level2_dom
.
xpath
(
'./text()'
)[
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(levels)
\ No newline at end of file
update_scrip.py
View file @
ea9a3d1c
import
sys
from
updateopera
import
Updater
import
importlib
from
utils.mysqlopera
import
COMPANY_PN_LIST
if
__name__
==
'__main__'
:
plat_name
=
sys
.
argv
[
1
]
module_name
=
'plat.{}.cate_stock'
.
format
(
plat_name
)
module
=
importlib
.
import_module
(
module_name
)
updater
=
Updater
(
plat_name
)
if
plat_name
in
[
'hc360'
]
:
if
plat_name
in
COMPANY_PN_LIST
:
updater
.
up_once
(
module
.
levels
)
else
:
updater
.
up
(
module
.
levels
)
updateopera.py
View file @
ea9a3d1c
from
utils.mysqlopera
import
MySqlOperator
from
utils.mysqlopera
import
MySqlOperator
,
COMPANY_PN_LIST
class
Updater
():
def
__init__
(
self
,
pn_name
):
self
.
operator
=
MySqlOperator
(
pn_name
)
self
.
table_name
=
'lie_'
+
pn_name
+
'_'
+
'category'
if
pn_name
in
[
'hc360'
]
else
'lie_category'
self
.
table_name
=
'lie_'
+
pn_name
+
'_'
+
'category'
if
pn_name
in
COMPANY_PN_LIST
else
'lie_category'
def
clean_db
(
self
):
with
self
.
operator
.
db
.
cursor
()
as
cursor
:
...
...
utils/mysqlopera.py
View file @
ea9a3d1c
...
...
@@ -4,7 +4,7 @@ import sys
import
time
import
pymysql
COMPANY_PN_LIST
=
[
'hc360'
,
'huangye88'
]
def
get_env
():
if
sys
.
platform
in
(
'darwin'
,
'win32'
):
...
...
@@ -28,7 +28,7 @@ UP_SET = {
def
get_mysql_conf
(
db
):
host
=
HOST_SET
[
ENV
]
if
db
in
[
'hc360'
]
:
if
db
in
COMPANY_PN_LIST
:
db
=
'bigdata'
if
ENV
==
'test'
:
host
=
HOST_SET
[
'test234'
]
...
...
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