【发布时间】:2022-01-22 11:28:46
【问题描述】:
我正在从 yahoo Finance(NVIDIA 股票)进行一些网络抓取,我想知道为什么当我运行我的代码时我总是得到相同的值,但是在我的浏览器中当我刷新页面时我得到不同的值(如它应该是),我该如何解决它?
import requests
from datetime import datetime
import time
def Is_Number(string):
try:
int(string)
return True
except:
if(string == '.'):
return True
else:
return False
session = requests.Session()
for i in range(10):
Response = session.get("https://finance.yahoo.com/quote/NVDA?p=NVDA")
KeyWord = 'data-pricehint'
Index = Response.text.find(KeyWord) + 26
GoOn = True
CurrentPrice = ""
while(GoOn == True):
if ( Is_Number(Response.text[Index])):
CurrentPrice = CurrentPrice + Response.text[Index]
Index = Index + 1
else:
GoOn = False
CurrentTime = datetime.now().strftime('%H:%M:%S')
print("# Price:",CurrentPrice,"at",CurrentTime)
time.sleep(10)
【问题讨论】:
标签: python web-scraping python-requests