|
- # -*- coding: utf-8 -*-
- # version: Python 3.7.0
- import parsel,requests,csv
- headers = {'User-Agent': '(KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
- base_url = 'https://www.365area.com/hscode/detail/'
- def get_detail_parse(code):
- r = requests.get(url=f'{base_url}{code}', headers=headers).content.decode('utf-8')
- sel = parsel.Selector(r).css('div.odd.green+div.even')
- my_list.append([code, sel.css('::text').re_first('\A\s*(.+?)\s*\Z')])
- if __name__ == '__main__':
- codes = ['3926909090',]#编码列表!!!
- my_list = [['编码', '申报要素']]
- for code in codes:
- get_detail_parse(code)
- with open(r'D:\result.csv', 'w', encoding="utf-8-sig", newline='') as f:
- csv.writer(f).writerows(my_list)
复制代码
|
|