为Finviz构建一个股票数据刮板。我使用的是通过Anaconda为python3.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
提前谢谢!你知道吗
每当你遇到这样一个不太合理的错误时,看看上面的一行:
结尾缺少一个右括号
)
。你知道吗相关问题 更多 >
编程相关推荐