Python 爬取道指成分股数据


代码来自中国大学慕课 用 Python 玩转数据

1
2
3
4
5
6
7
8
9
10
11
import requests
import re

def retrieve_dji_list():
r = requests.get('http://money.cnn.com/data/dow30/')
search_pattern = re.compile('class="wsod_symbol">(.*)<\/a>.*<span.*">(.*?)<\/span>.*\n.*class="wsod_stream">(.*)<\/span>')
dji_list_in_text = re.findall(search_pattern, r.text)
return dji_list_in_text

dji_list = retrieve_dji_list()
print(dji_list)

参考文档:
用 Python 玩转数据