【发布时间】:2019-01-29 17:28:24
【问题描述】:
为 Finviz 构建股票数据抓取工具。我正在使用通过 Anaconda 为 Python 3.7 安装的 Spyder3。
我的代码如下。当我在终端中逐行执行 x = 0,然后 x = x+1 代码时,它工作得很好。当我运行整个脚本时,如果我使用 x += 1 或 x = x + 1,我会得到同样的错误。
def finviz_query(tickerlist):
'''Get's source code from FinViz and Creates a List of Lists for Export '''
url="https://finviz.com/screener.ashx?v=140&t=" + str(stocks)
response = requests.get(url)
source=response.text
soup = bs4.BeautifulSoup(source)
priceLST = [i.get_text() for i in soup.find_all('a')]
del priceLST[0:37]
del priceLST[len(priceLST)-2:len(priceLST)]
stockLST = re.split(',',stocks)
stock_outputLST = []
while len(priceLST) > 0:
if priceLST[0] in stockLST:
stock_outputLST.append([priceLST[0:16]])
del priceLST[0:16]
if len(priceLST) < 1:
break
x = 0
while x < len(stock_outputLST):
if x < len(stock_outputLST):
stock_outputLST[x][0].append(time.strftime("%Y-%m-%d;%H:%M")
x = x + 1
else:
break
stock_outputLST[len(stock_outputLST)-1][0].append('0')
stock_outputLST[len(stock_outputLST)-1][0].append(time.strftime("%Y-%m-%d;%H:%M"))
错误输出在这里:
...:stock_outputLST[len(stock_outputLST)-1][0].append(time.strftime("%Y-%m-%d;%H:%M"))
...: return print('finviz_query complete')
File "<ipython-input-114-81b306b1a6de>", line 22
x = x + 1
^
SyntaxError: invalid syntax
提前致谢!
【问题讨论】:
-
像往常一样,您在上一行缺少一个近括号。
-
非常感谢。格雷格也做出了同样的回应。你们可以这么快就看到这些东西,真是太神奇了。
标签: python python-3.x anaconda spyder