1
介绍一下如何用python采集选股宝的涨停信息——主要是涨停原因数据,以便在本地进行后续统计分析。
用到的开发工具 python3.6、pycharm、chrome
2
先用chrome找到选股宝涨停数据的网址,可以看到是个API——
https://flash-api.xuangubao.cn/api/pool/detail?pool_name=limit_up
直接访问API网址就能看到数据。
用request去获取,再进行解析就可以了。
3
为了方便复用,我们把访问网址获取数据功能放在一个类里,文件名collector.py,类名为Collector
import urllib.request
import http.cookiejar
import time
class Collector(object):
def __init__(self):
self.cookies = http.cookiejar.CookieJar()
self.handler=urllib.request.HTTPCookieProcessor(self.cookies)
self.opener = urllib.request.build_opener(self.handler)
def requestURL(self,url):
retryCount = 200
while retryC