Commit b48bbf42 by lichenggang

add mfqyw

parent b53a3a05
File mode changed
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",
}
a = Module_Base()
url = 'http://www.mfqyw.com/sell/list-htm-catid-4.html'
resp = a.requests.get(url,headers=headers).text
dom = a.etree.HTML(resp)
level2_doms=dom.xpath('//div[@class="category"]//td//a')
levels=[]
level1={}
level1['cat_name'] = '电工电气'
level1['url'] = 'http://www.mfqyw.com/sell/list-htm-catid-4.html'
level1['level'] = 1
level1['islast'] = 0
level1['parent_id'] = 0
level1['level2_list'] = []
# print('一级分类',level1)
# level2_doms = dom.xpath('.//a')
# print(len(level2_doms))
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
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