【发布时间】:2016-03-09 01:48:09
【问题描述】:
我是 Python 编程新手。我正在尝试获取符号和时间。
我能够获得适合我的时间。它只出现第一个词,有时是一个时间,而不是“之后/之前”市场关闭。
但是当涉及到符号时,我不想要任何外国市场,所以没有 .??在符号中。这是我到目前为止所拥有的。对不起,如果它有点草率。这是我在 python 中的第一个真正的程序....
import requests
import urllib2
import re
from bs4 import BeautifulSoup
site= "http://www.nasdaq.com/earnings/report/acrx"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8'}
url = "http://biz.yahoo.com/research/earncal/20150309.html"
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content)
m = re.findall('center><small>\S+ ', content)
w = re.findall('\?s=\w+',content)
x=0
lp = (len(m))
xlp = lp -1
for x in range (xlp):
print x, m[x+1][14:], w[x][3:]
【问题讨论】:
标签: python web-scraping yahoo-finance