【发布时间】:2017-05-16 04:27:29
【问题描述】:
以下是在网站上搜索单词的脚本。在这种情况下,它是https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC 上的“S&P”。
我的问题是如何搜索 2300 到 2400 之间的数字范围......或小于/大于 2400 的数字。基本上,我正在制作一个脚本,告诉我价格何时达到某个点.
感谢您的帮助!
import webbrowser
import urllib.request
page = urllib.request.urlopen("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC")
content = page.read().decode('utf-8')
if "S&P" in content :
webbrowser.open("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC")
2017 年 5 月 16 日更新 下面的人帮助了我。感谢并感谢所有回复。我修修补补并在下面做了。
import urllib.request
import webbrowser
from bs4 import BeautifulSoup
page = urllib.request.urlopen("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC")
content = page.read().decode('utf-8')
soup = BeautifulSoup(content, 'html.parser')
val = soup.find("span", {"data-reactid": "36"}).decode_contents(formatter="html")
if val >= "2,400.00":
webbrowser.open("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC")
【问题讨论】:
标签: python-3.x if-statement numbers range