def getSignleStockShortInfo(stock):
df = pd.DataFrame()
url = "http://shortsqueeze.com/?symbol=" + stock + "&submit=Short+Quote%E2%84%A2"
repeat_times = 3
downloadFailed = True
for _ in range(repeat_times):
try:
response = requests.get(url, timeout=15)
downloadFailed = False
break
except Exception as e:
print ("exception in get stock:" + stock, str(e))
continue
if downloadFailed:
return "", df
try:
tables = pd.read_html(response.text, attrs={'cellpadding': '3', 'width': '100%'})
except Exception as e:
print ("exception in parse stock:" + stock, str(e))
return "", df
for table in tables:
if df.empty:
df = table
else:
df = pd.concat([df, table])
df = df.reset_index(drop=True, inplace=True)
#print(df)
soup = BeautifulSoup(response.text, 'lxml')
dateString = soup.find('span', {"style" : "color:#999999;font-family: verdana, arial, helvetica;font-size:10px"}).get_text()
date = datetime.datetime.strptime(dateString, '%A %B %d, %Y')
return date, df.T
Fetch_Data_Stock_US_Short.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录