snowball.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Xueqiu 作者: OliangchenO 项目源码 文件源码
def get_xueqiu_hold(cube_symbol,cube_weight):
    db = TinyDB('data/db_holding.json')
    print(cube_symbol)
    table = db.table(cube_symbol)
    db.purge_table(cube_symbol)
    req = urllib.request.Request(cube_hold_url+cube_symbol,headers = {
                'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:33.0) Gecko/20100101 Firefox/33.0',
                'cookie':cookie
               })
    soup = urllib.request.urlopen(req).read().decode('utf-8')
    soup = BeautifulSoup(soup, 'lxml')
    script = soup.find('script', text=re.compile('SNB\.cubeInfo'))
    json_text = re.search(r'^\s*SNB\.cubeInfo\s*=\s*({.*?})\s*;\s*$',
                      script.string, flags=re.DOTALL | re.MULTILINE).group(1)
#     json_text.append({'cube_symbol':cube_symbol}).append({'cube_weight':cube_weight})
    data = json.loads(json_text)
#     data.update({'cube_symbol',cube_symbol}).update({'cube_weight',cube_weight})
#     data["view_rebalancing"]["holdings"].append("cube_symbol : "+cube_symbol)
#     data["view_rebalancing"]["holdings"].append("cube_weight : "+cube_weight)
#     print(data["view_rebalancing"]["holdings"])
#     data["view_rebalancing"]["holdings"]
    table.insert({"cube_symbol":data["view_rebalancing"]["holdings"]})
#     for row in table:
#         print(row)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号