- 帖子
- 1
- 精华
- 0
- 积分
- 4
- 阅读权限
- 10
- 注册时间
- 2015-6-11
- 最后登录
- 2015-6-11
|
我用的是request包。感觉比urllib2要简单一些。- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36'}
- url = 'http://xueqiu.com/p/ZH297574'
- x = requests.get(url,headers=headers)
- html = x.text
- pos_start = html.find('SNB.cubeInfo = ') + 15
- pos_end = html.find('SNB.cubePieData')
- data = html[pos_start:pos_end]
- dic = json.loads(data)
复制代码 但是我现在遇到的一个问题是python2里面的unicode的问题。
我直接printdic['view_rebalancing']['holdings'][0]的时候,得到的是
{u'stock_id': 1008310, 。。。 u'segment_name': u'\u533b\u836f\u533b\u7597', u'stock_symbol': u'AKBA', u'proactive': False}
如果我直接打
dic['view_rebalancing']['holdings'][0]['segment_name']
出来的就是 ‘医药医疗’
用的都是print方法。这个要怎么解决啊。
|
|