2017-05-16 10 views
0

以下は、ウェブサイト上の単語を検索するスクリプトです。この場合、https://finance.yahoo.com/quote/%5EGSPC?p=^GSPCの "S & P"です。検索番号Pythonのウェブサイトの範囲

私の質問は、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") 

updated 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") 

答えて

0

BeautifulSoupで次のことを試してみてください。

>>> import urllib2 
>>> from bs4 import BeautifulSoup 
>>> page = urllib2.urlopen("https://finance.yahoo.com/quote/%5EGSPC?p=^GSPC") 
>>> page = urllib2.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") 
>>> val 
u'2,402.32' 
>>> 

その後、それはあなたのブレークポイントと一致するかどうかをチェックするためにfloat型に変換します。

>>> val = float(val.replace(',','')) 
>>> val 
2402.32 
>>> 
0

あなたはBS4の美しいスープを使用することができます。 pipを使用してインストールします。

from bs4 import BeautifulSoup as soup 
content=soup(content,'lxml') 
stuffs=content.findAll(class_="Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(ib)") 
#stuffs will contain your stock price. you can check what range its in and stuff with it