Commit 47cc77af by lichenggang

add oneyac

parent 864da817
#!/usr/bin/env python
# -*- coding:utf-8 -*-
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from utils.base import Module_Base
domain='http://product.114ic.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://product.114ic.com/'
resp = a.requests.get(url,headers=headers).text
dom = a.etree.HTML(resp)
level1_doms=dom.xpath('//div[@class="s_pronavitem"]/div')
levels=[]
for level1_dom in level1_doms:
level1=dict()
level1['cat_name'] = level1_dom.xpath('./h3/a/text()')[0]
level1['url'] = domain+level1_dom.xpath('./h3/a/@href')[0]
level1['level'] = 1
level1['islast'] = 0
level1['parent_id'] = 0
level1['level2_list'] = []
# print('一级分类',level1)
level2_doms = level1_dom.xpath('.//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)
levels.append(level1)
# print(levels)
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
\ No newline at end of file
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from utils.base import Module_Base
from utils.proxy_util import proxies
url = 'http://www.oneyac.com/search/product_category.html'
a = 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",
}
resp = a.requests.get(url, headers=headers,proxies=proxies).text
doms = a.etree.HTML(resp)
level1_1 = doms.xpath('//p[@class="catg-itm__cap"]//a')
level1_2 = doms.xpath('//ul[@class="catg-sLst clear"]')
level1 = zip(level1_1,level1_2)
levels = []
for content_dom in level1:
level1 = dict()
level1['cat_name'] = content_dom[0].xpath('./text()')[0].strip()
level1['url'] = content_dom[0].xpath('./@href')[0].strip()
level1['level'] = 1
level1['islast'] = 0
level1['parent_id'] = 0
level1['level2_list'] = []
print('一级分类',level1['cat_name'])
level2_doms = content_dom[1].xpath('.//li')
for level2_dom in level2_doms:
level2 = {}
level2['cat_name'] = level2_dom.xpath('.//a/text()')[0]
level2['url'] = level2_dom.xpath('.//a/@href')[0]
level2['level'] = 2
level2['islast'] = 1
level1['level2_list'].append(level2)
print('二级分类',level2['cat_name'])
levels.append(level1)
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