我已經閱讀過這個問題(Python HTML parsing from url),但我還沒有理解。這是代碼:HTML解析:從源代碼到Python中的文本
import urllib.request
from html.parser import HTMLParser
# create a subclass and override the handler methods
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print ("Encountered a start tag:"+ tag)
def handle_endtag(self, tag):
print ("Encountered an end tag :"+ tag)
def handle_data(self, data):
print ("Encountered some data :"+ data)
parser = MyHTMLParser()
info = "http://www.calendario-365.it/js/365.php?page=moon"
response = urllib.request.urlopen(info)
content = response.read()
parser.feed(str(content))
應用此代碼到我的網站給我: http://pastebin.com/m4YV38uM 我想保存到變量
10,6 giorni
82%
如何?感謝您的回答。 Python版本:3.5。
這不是一個答案......如果您打算從OP獲取更多信息,請將其作爲評論發佈,否則如果您不能,請不要將其作爲答案發布。 –
這兩個元素每天都可以改變,例如「54%」或「100%」之後的「82%」。也許「%」之前的兩個(或3個)數字?或者可能是「giorni」之前的三位數字?我不知道是否有真正的標準:) – MarcoBuster
@鐵拳:我的壞,我是新來的。這並不是要回答。似乎它不讓我評論,因爲低地位,雖然... – patrick