0
我想從雅虎財經獲取漂亮指數的價格。我正在使用此代碼:如何獲得^ NSEI的股票價格
import urllib
import re
url= 'https://in.finance.yahoo.com/q?s=^nsei'
htmlfile=urllib.urlopen(url)
htmltext =htmlfile.read()
regex ='<span id="yfs_l10_^nsei">(.+?)</span>'
pattern = re.compile(regex)
price =re.findall(pattern,htmltext)
print price
但輸出是一個空列表。我的代碼有什麼問題?
不是'quote'但是轉義 – cat
修正了這個問題。儘管如此,Downvote蒼蠅不必要 –
另一種方法是使用原始字符串。因此,只需'r'(。+?)''就是你需要的所有 – smac89