1. 便捷数据获取

  1.2 网络数据获取:

    1.2.1 urllib, urllib2, httplib, httplib2和正则表达式(python3中为urllib.request, http.client)

In [179]: import urllib2,re

In [180]: dStr = urllib2.urlopen('https://hk.finance.yahoo.com/q/cp?s=%5EDJI').read()

In [181]: m = re.findall('<tr><td class="yfnc_tabledata1"><b><a href=".*?">(.*?)</a></b></td><td class="yfnc_tabledata1">(.*?)</td>.*?<b>(.*?)</b>.*?</tr>',dStr)

In [182]: m
Out[182]: 
[('AAPL', '\xe8\x98\x8b\xe6\x9e\x9c\xe5\x85\xac\xe5\x8f\xb8', '120.000'),
 ('AXP', 'American Express Company', '76.200'),
 ('BA', 'The Boeing Company', '159.530'),
...
 ('XOM', 'Exxon Mobil Corporation', '85.890')]
View Code

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
  • 2021-12-07
  • 2021-12-23
  • 2021-06-13
猜你喜欢
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-02-10
  • 2022-12-23
相关资源
相似解决方案