#!/usr/bin/env python
import urllib2
import re
file_url='http://money.163.com/forex/'
f=urllib2.urlopen(file_url).read()
p=re.compile(r'<option\svalue="..">(.*?)</option>',re.U|re.S) #问号表示不是贪婪匹配
results=p.findall(f)
for result in results:
import urllib2
import re
file_url='http://money.163.com/forex/'
f=urllib2.urlopen(file_url).read()
p=re.compile(r'<option\svalue="..">(.*?)</option>',re.U|re.S) #问号表示不是贪婪匹配
results=p.findall(f)
for result in results:
print result.decode("gb2312").encode("UTF-8") #gb2312是网页的编码,我们转换为UTF-8格式
输出结果为:
股票
基金
期货
港股
美股
外汇