鱼C论坛

 找回密码
 立即注册
查看: 1563|回复: 8

[已解决]求爬虫大佬来看看

[复制链接]
发表于 2021-1-4 15:26:47 | 显示全部楼层 |阅读模式
10鱼币
本帖最后由 头发 于 2021-1-4 15:57 编辑

ARRFUTURESNODES = {
    czce : ['郑州商品交易所', ['PTA', 'pta_qh', '16'],['菜油', 'czy_qh', '18'], ['菜籽', 'ycz_qh', '18'], ['菜粕', 'czp_qh', '18'],['动力煤', 'dlm_qh', '18'],
        ['强麦', 'qm_qh', '3'],['粳稻', 'jdm_qh', '3'], ['白糖', 'bst_qh', '15'], ['棉花', 'mh_qh', '7'], ['早籼稻', 'zxd_qh', '23'], ['郑醇', 'zc_qh', '27'],['玻璃', 'bl_qh', '27'],['晚籼稻','wxd_qh','27'],['硅铁','gt_qh','27'],['锰硅','mg_qh','27'], ['棉纱', 'ms_qh', '9'], ['鲜苹果', 'xpg_qh', '27'], ['红枣', 'hz_qh', '27'],['尿素', 'ns_qh', '27'],['纯碱', 'cj_qh', '27'],['短纤', 'pf_qh', '27']],
    dce : ['大连商品交易所', ['PVC', 'pvc_qh', '24'], ['棕榈', 'zly_qh', '0'], ['豆二', 'de_qh', '10'], ['豆粕', 'dp_qh', '9'], ['铁矿石', 'tks_qh', '9'],['鸡蛋', 'jd_qh', '9'],
        ['塑料', 'lldpe_qh', '2'],['PP', 'jbx_qh', '2'],['纤维板', 'xwb_qh', '2'],['胶合板', 'jhb_qh', '2'], ['豆油', 'dy_qh', '14'], ['玉米', 'hym_qh', '12'], ['豆一', 'dd_qh', '8'],['焦炭', 'jt_qh', '26'],['焦煤', 'jm_qh', '26'],['玉米淀粉', 'ymdf_qh', '26'],['乙二醇', 'yec_qh', '26'], ['粳米', 'gm_qh', '26'], ['苯乙烯', 'byx_qh', '30']],
    shfe : ['上海期货交易所', ['燃油', 'ry_qh', '13'], ['原油', 'yy_qh', '30'], ['沪铝', 'lv_qh', '1'], ['橡胶', 'xj_qh', '4'], ['沪锌', 'xing_qh', '17'],
        ['沪铜', 'tong_qh', '5'], ['黄金', 'hj_qh', '19', 'futures.fu_dig2'], ['螺纹钢', 'lwg_qh', '21'], ['线材', 'xc_qh', '22'],
        ['沪铅','qian_qh','25'],['白银','by_qh','25'],['沥青','lq_qh','25'],['热轧卷板','rzjb_qh','14'],['沪锡','xi_qh','21'],['沪镍','ni_qh','21'], ['纸浆','zj_qh','21'], ['20号胶','ehj_qh','21'], ['不锈钢','bxg_qh','21'], ['低硫燃料油','lu_qh','21'], ['国际铜','bc_qh','21']],
};

如何将嵌套列表中的中间的数据爬出来存进一个新列表中呀???如加红的字体所示(不是指爬红色字体)
币不多,以表心意
最佳答案
2021-1-4 15:26:48
改了一下楼上的代码,输出效果好多了
ARRFUTURESNODES = {
    'czce' : ['郑州商品交易所', ['PTA', 'pta_qh', '16'],['菜油', 'czy_qh', '18'], ['菜籽', 'ycz_qh', '18'], ['菜粕', 'czp_qh', '18'],['动力煤', 'dlm_qh', '18'],
        ['强麦', 'qm_qh', '3'],['粳稻', 'jdm_qh', '3'], ['白糖', 'bst_qh', '15'], ['棉花', 'mh_qh', '7'], ['早籼稻', 'zxd_qh', '23'], ['郑醇', 'zc_qh', '27'],['玻璃', 'bl_qh', '27'],['晚籼稻','wxd_qh','27'],['硅铁','gt_qh','27'],['锰硅','mg_qh','27'], ['棉纱', 'ms_qh', '9'], ['鲜苹果', 'xpg_qh', '27'], ['红枣', 'hz_qh', '27'],['尿素', 'ns_qh', '27'],['纯碱', 'cj_qh', '27'],['短纤', 'pf_qh', '27']],
    'dce' : ['大连商品交易所', ['PVC', 'pvc_qh', '24'], ['棕榈', 'zly_qh', '0'], ['豆二', 'de_qh', '10'], ['豆粕', 'dp_qh', '9'], ['铁矿石', 'tks_qh', '9'],['鸡蛋', 'jd_qh', '9'],
        ['塑料', 'lldpe_qh', '2'],['PP', 'jbx_qh', '2'],['纤维板', 'xwb_qh', '2'],['胶合板', 'jhb_qh', '2'], ['豆油', 'dy_qh', '14'], ['玉米', 'hym_qh', '12'], ['豆一', 'dd_qh', '8'],['焦炭', 'jt_qh', '26'],['焦煤', 'jm_qh', '26'],['玉米淀粉', 'ymdf_qh', '26'],['乙二醇', 'yec_qh', '26'], ['粳米', 'gm_qh', '26'], ['苯乙烯', 'byx_qh', '30']],
    'shfe' : ['上海期货交易所', ['燃油', 'ry_qh', '13'], ['原油', 'yy_qh', '30'], ['沪铝', 'lv_qh', '1'], ['橡胶', 'xj_qh', '4'], ['沪锌', 'xing_qh', '17'],
        ['沪铜', 'tong_qh', '5'], ['黄金', 'hj_qh', '19', 'futures.fu_dig2'], ['螺纹钢', 'lwg_qh', '21'], ['线材', 'xc_qh', '22'],
        ['沪铅','qian_qh','25'],['白银','by_qh','25'],['沥青','lq_qh','25'],['热轧卷板','rzjb_qh','14'],['沪锡','xi_qh','21'],['沪镍','ni_qh','21'], ['纸浆','zj_qh','21'], ['20号胶','ehj_qh','21'], ['不锈钢','bxg_qh','21'], ['低硫燃料油','lu_qh','21'], ['国际铜','bc_qh','21']],
};

for i in ARRFUTURESNODES.values():
    for test in i:
        print(' '.join(test) if isinstance(test, list) else test)

最佳答案

查看完整内容

改了一下楼上的代码,输出效果好多了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 15:26:48 | 显示全部楼层    本楼为最佳答案   
改了一下楼上的代码,输出效果好多了
ARRFUTURESNODES = {
    'czce' : ['郑州商品交易所', ['PTA', 'pta_qh', '16'],['菜油', 'czy_qh', '18'], ['菜籽', 'ycz_qh', '18'], ['菜粕', 'czp_qh', '18'],['动力煤', 'dlm_qh', '18'],
        ['强麦', 'qm_qh', '3'],['粳稻', 'jdm_qh', '3'], ['白糖', 'bst_qh', '15'], ['棉花', 'mh_qh', '7'], ['早籼稻', 'zxd_qh', '23'], ['郑醇', 'zc_qh', '27'],['玻璃', 'bl_qh', '27'],['晚籼稻','wxd_qh','27'],['硅铁','gt_qh','27'],['锰硅','mg_qh','27'], ['棉纱', 'ms_qh', '9'], ['鲜苹果', 'xpg_qh', '27'], ['红枣', 'hz_qh', '27'],['尿素', 'ns_qh', '27'],['纯碱', 'cj_qh', '27'],['短纤', 'pf_qh', '27']],
    'dce' : ['大连商品交易所', ['PVC', 'pvc_qh', '24'], ['棕榈', 'zly_qh', '0'], ['豆二', 'de_qh', '10'], ['豆粕', 'dp_qh', '9'], ['铁矿石', 'tks_qh', '9'],['鸡蛋', 'jd_qh', '9'],
        ['塑料', 'lldpe_qh', '2'],['PP', 'jbx_qh', '2'],['纤维板', 'xwb_qh', '2'],['胶合板', 'jhb_qh', '2'], ['豆油', 'dy_qh', '14'], ['玉米', 'hym_qh', '12'], ['豆一', 'dd_qh', '8'],['焦炭', 'jt_qh', '26'],['焦煤', 'jm_qh', '26'],['玉米淀粉', 'ymdf_qh', '26'],['乙二醇', 'yec_qh', '26'], ['粳米', 'gm_qh', '26'], ['苯乙烯', 'byx_qh', '30']],
    'shfe' : ['上海期货交易所', ['燃油', 'ry_qh', '13'], ['原油', 'yy_qh', '30'], ['沪铝', 'lv_qh', '1'], ['橡胶', 'xj_qh', '4'], ['沪锌', 'xing_qh', '17'],
        ['沪铜', 'tong_qh', '5'], ['黄金', 'hj_qh', '19', 'futures.fu_dig2'], ['螺纹钢', 'lwg_qh', '21'], ['线材', 'xc_qh', '22'],
        ['沪铅','qian_qh','25'],['白银','by_qh','25'],['沥青','lq_qh','25'],['热轧卷板','rzjb_qh','14'],['沪锡','xi_qh','21'],['沪镍','ni_qh','21'], ['纸浆','zj_qh','21'], ['20号胶','ehj_qh','21'], ['不锈钢','bxg_qh','21'], ['低硫燃料油','lu_qh','21'], ['国际铜','bc_qh','21']],
};

for i in ARRFUTURESNODES.values():
    for test in i:
        print(' '.join(test) if isinstance(test, list) else test)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 15:31:13 | 显示全部楼层
print(ARRFUTURESNODES['czce'][1][1])
print(ARRFUTURESNODES['czce'][2][1])
print(ARRFUTURESNODES['shfe'][-1][1])
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-1-4 15:32:22 | 显示全部楼层

谢谢 是所有的中间的数据,加红的是示例
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 15:41:41 | 显示全部楼层
头发 发表于 2021-1-4 15:32
谢谢 是所有的中间的数据,加红的是示例


以后一次性说清楚:
result = []
for v in ARRFUTURESNODES.values():
    for item in v[1:]:
        result.append(item[1])
print(result)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-1-4 15:48:13 | 显示全部楼层
suchocolate 发表于 2021-1-4 15:41
以后一次性说清楚:

简单组合了下 运行不了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 16:12:27 | 显示全部楼层
ARRFUTURESNODES = {
    'czce' : ['郑州商品交易所', ['PTA', 'pta_qh', '16'],['菜油', 'czy_qh', '18'], ['菜籽', 'ycz_qh', '18'], ['菜粕', 'czp_qh', '18'],['动力煤', 'dlm_qh', '18'],
        ['强麦', 'qm_qh', '3'],['粳稻', 'jdm_qh', '3'], ['白糖', 'bst_qh', '15'], ['棉花', 'mh_qh', '7'], ['早籼稻', 'zxd_qh', '23'], ['郑醇', 'zc_qh', '27'],['玻璃', 'bl_qh', '27'],['晚籼稻','wxd_qh','27'],['硅铁','gt_qh','27'],['锰硅','mg_qh','27'], ['棉纱', 'ms_qh', '9'], ['鲜苹果', 'xpg_qh', '27'], ['红枣', 'hz_qh', '27'],['尿素', 'ns_qh', '27'],['纯碱', 'cj_qh', '27'],['短纤', 'pf_qh', '27']],
    'dce' : ['大连商品交易所', ['PVC', 'pvc_qh', '24'], ['棕榈', 'zly_qh', '0'], ['豆二', 'de_qh', '10'], ['豆粕', 'dp_qh', '9'], ['铁矿石', 'tks_qh', '9'],['鸡蛋', 'jd_qh', '9'],
        ['塑料', 'lldpe_qh', '2'],['PP', 'jbx_qh', '2'],['纤维板', 'xwb_qh', '2'],['胶合板', 'jhb_qh', '2'], ['豆油', 'dy_qh', '14'], ['玉米', 'hym_qh', '12'], ['豆一', 'dd_qh', '8'],['焦炭', 'jt_qh', '26'],['焦煤', 'jm_qh', '26'],['玉米淀粉', 'ymdf_qh', '26'],['乙二醇', 'yec_qh', '26'], ['粳米', 'gm_qh', '26'], ['苯乙烯', 'byx_qh', '30']],
    'shfe' : ['上海期货交易所', ['燃油', 'ry_qh', '13'], ['原油', 'yy_qh', '30'], ['沪铝', 'lv_qh', '1'], ['橡胶', 'xj_qh', '4'], ['沪锌', 'xing_qh', '17'],
        ['沪铜', 'tong_qh', '5'], ['黄金', 'hj_qh', '19', 'futures.fu_dig2'], ['螺纹钢', 'lwg_qh', '21'], ['线材', 'xc_qh', '22'],
        ['沪铅','qian_qh','25'],['白银','by_qh','25'],['沥青','lq_qh','25'],['热轧卷板','rzjb_qh','14'],['沪锡','xi_qh','21'],['沪镍','ni_qh','21'], ['纸浆','zj_qh','21'], ['20号胶','ehj_qh','21'], ['不锈钢','bxg_qh','21'], ['低硫燃料油','lu_qh','21'], ['国际铜','bc_qh','21']],
};

for i in ARRFUTURESNODES.values():
    for test in i:
        # print(test)
        for testNum in test:
            print(testNum)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 16:13:05 | 显示全部楼层
头发 发表于 2021-1-4 15:48
简单组合了下 运行不了

字典变量定义有错误。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-1-4 17:11:42 | 显示全部楼层
头发 发表于 2021-1-4 15:48
简单组合了下 运行不了

你的字典键改成字符串,尾部去掉;
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 20:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表