python爬取上海期货交易所数据

一:爬虫的常规方法

爬虫的常用套路是table-tr(行)-th/td(元素)


'''
Created on Feb 28, 2017


@author: hcq908
'''
import csv
import os
# import re
from urllib.request import urlopen
from bs4 import BeautifulSoup


if __name__ == '__main__':
    iCntTable = 0;
    html = urlopen("https://en.wikipedia.org/wiki/Comparison_of_text_editors")
    #html = urlopen("http://www.shfe.com.cn/bourseService/businessdata/summaryinquiry/index.html?paramid=trading_daily")
    bsObj = BeautifulSoup(html, "html.parser")
    oTables = bsObj.find_all("table")#选定第一个表格
    for table in oTables:
        iCntTable  =iCntTable + 1;
        print('处理第%d个表格 \n'%iCntTable)
        #获取表格名称
        #sTitleTag = table.find('caption');#标题只有一个,注意有的没有标题等
        #print(sTitleTag)
    #     sMatchText = re.compile(r'<[^>]+>', re.S)
    #     sTextRemain = sMatchText.sub('', sTitleTag)
        sTitleName=  chr(iCntTable)+'.csv';
        
        #路劲不存在是需要新建
        sDir = './files';
        if not os.path.exists(s
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值