作业
程序员文章站
2022-04-20 18:27:33
...
作业
雪球网。搜索土耳其ETF-iShares MSCI(NASDAQ:TUR)
看到上图,最后右键—-检查元素
begin=,end=就是时间戳,只要改这两个时间就可以得到以下想要的内容,先看下部分内容
item:后面的内容就是想要的数据,简单正则pattern = re.compile(r’[[.*]]’),,,,resu = pattern.search(r.text)。resu就可以得到想要的内容。
详细代码如下:
requests.packages.urllib3.disable_warnings()
headers = {
'Cookie': '''xq_a_token=aef774c17d4993658170397fcd0faedde488bd20; xq_a_token.sig=F7BSXzJfXY0HFj9lqXif9IuyZhw; xq_r_token=d694856665e58d9a55450ab404f5a0144c4c978e; xq_r_token.sig=Ozg4Sbvgl2PbngzIgexouOmvqt0; _ga=GA1.2.1898661250.1534100725; _gid=GA1.2.1857601942.1534100725; Hm_lvt_1db88642e346389874251b5a1eded6e3=1534100726; u=591534100726653; device_id=45cf44f49947d53b197f7eaa09f5a915; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1534101390''',
'Host':'stock.xueqiu.com',
'Origin':'https://xueqiu.com',
'Upgrade-Insecure-Requests':'https://xueqiu.com/S/TUR',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36 OPR/54.0.2952.64'
}
if __name__ == '__main__':
ssl._create_default_https_context = ssl._create_unverified_context
url = 'https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=TUR&begin=1199163600&end=1534101411857&period=day&type=before&indicator=kline'
copy_csv = open('宇宙探索.csv', 'a+', newline='')
fieldnames = ["timestamp", "volume", "open", "high", "low", "close", "chg", "percent", "turnoverrate"]
wr_pool = csv.writer(copy_csv)
wr_pool.writerow(fieldnames)
url = 'https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=TUR&begin=1199163600&end=1534101411857&period=day&type=before&indicator=kline'
r = requests.get(url, headers = headers ,verify = False)
pattern = re.compile(r'\[\[.*\]\]')
resu = pattern.search(r.text)
js_result = json.loads(resu.group())
if js_result:
for jj in range(0, len(js_result)):
timeTuple = time.localtime(js_result[jj][0]/1000)
otherStyleTime = time.strftime("%Y-%m-%d %H:%M:%S", timeTuple)
js_result[jj][0] = otherStyleTime
wr_pool.writerow(js_result[jj])
copy_csv.close()
begin=1199163600,就是2008年1月1日的时间戳,&end=1534101411857就是2018年8月10日的时间戳。获取到的数据挺大的感觉,耗费一点时间。程序差点死掉。接下来就是用csv保存
上一篇: photoshop设计制作出黎明前在湖边相拥亲吻的约会壁纸
下一篇: 当我请你吃了