搜狐股票动态数据的抓取
#http://q.stock.sohu.com/cn/000078/lshq.shtml
import urllib.request import re import json import csv url = 'http://q.stock.sohu.com/hisHq?code=cn_000078&start=20161201&end=20170330&stat=1&order=D&period=d&callback=historySearchHandler&rt=jsonp&r=0.543412915586595&0.7723848901142324' html = urllib.request.urlopen(url).read() html = html.decode('gbk') html = html[21:-2]#去BOM头 data = json.loads(html) datalist = data[0]['hq'] with open('02.csv', "w",newline='') as csvFile: csvWriter = csv.writer(csvFile) for data in datalist: csvWriter.writerow(data) csvFile.close