Commit 19bf894c by lichenggang

add x51sole

parent 7e0f33f7
from utils.base import Module_Base
import aiohttp
from asyncio import get_event_loop
import asyncio
domain='http://www.eastsoo.com'
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()
url = 'http://www.eastsoo.com/buy/dianzi.html'
resp = a.requests.get(url,headers=headers).text
dom = a.etree.HTML(resp)
level1_doms=dom.xpath('//li[@class="x2"]')
async def get_resps(level1):
async with aiohttp.ClientSession() as sess:
async with sess.get(level1['url'],headers=headers) as response:
text = await response.text()
# text = a.requests.get(level1['url'],headers=headers).text
dom = a.etree.HTML(text)
level2_doms = dom.xpath('//ul[@class="x10 change-size"]//li/a')
for level2_dom in level2_doms:
level2 = {}
level2['cat_name'] = level2_dom.xpath('./text()')[0]
level2['url'] = domain+level2_dom.xpath('./@href')[0]
level2['level'] = 2
level2['islast'] = 1
level1['level2_list'].append(level2)
# print('二级分类', level2)
return level1
async def get_levels():
levels = []
for level1_dom in level1_doms:
level1=dict()
level1['cat_name'] = level1_dom.xpath('.//a/text()')[0]
level1['url'] = domain+level1_dom.xpath('.//a/@href')[0]
level1['level'] = 1
level1['islast'] = 0
level1['parent_id'] = 0
level1['level2_list'] = []
# print('一级分类',level1)
level1_ok = await get_resps(level1)
levels.append(level1_ok)
return levels
loop=get_event_loop()
loop.run_until_complete(get_levels)
levels = get_levels()
print(levels)
\ No newline at end of file
File mode changed
File mode changed
from utils.base import Module_Base
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()
url = 'http://ec.51sole.com/'
resp = a.requests.get(url,headers=headers).text
dom = a.etree.HTML(resp)
level1_doms1=dom.xpath('//div[@class="type"]//h2')
level1_doms2=dom.xpath('//div[@class="type"]//p[@class="cgray"]')
level1_doms = zip(level1_doms1,level1_doms2)
def get_levels():
levels = []
for level1_dom in level1_doms:
level1=dict()
level1['cat_name'] = level1_dom[0].xpath('.//a/text()')[0].strip()
level1['url'] = domain+level1_dom[0].xpath('.//a/@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'] = domain + level2_dom.xpath('./@href')[0]
level2['level'] = 2
level2['islast'] = 1
level1['level2_list'].append(level2)
levels.append(level1)
return levels
levels = get_levels()
print(levels)
\ No newline at end of file
...@@ -5,7 +5,7 @@ import time ...@@ -5,7 +5,7 @@ import time
import pymysql import pymysql
COMPANY_PN_LIST = ['hc360', 'huangye88', 'pangwo', 'coovee', 'liebiao', 'china', 'ic114', 'cecb2b', 'trustexporter', 'x11467', 'x912688', 'zgtghccl', 'herostart', 'testmart', 'cc'] COMPANY_PN_LIST = ['hc360', 'huangye88', 'pangwo', 'coovee', 'liebiao', 'china', 'ic114', 'cecb2b', 'trustexporter', 'x11467', 'x912688', 'zgtghccl', 'herostart', 'testmart', 'cc', 'eastsoo', 'x51sole']
def get_env(): def get_env():
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment