2016-11-28 56 views
-3

我在學習蟒蛇 新我有這些信息這個網站頁面:如何使用python讀取html頁面?

enter image description here

我想讀的HTML頁面和打印這樣的信息:

['2011/2016', 'aaaa', 'x-t ', 'htu ', '***' , '55'] 
+0

你需要[美麗的湯(https://www.crummy.com/software/BeautifulSoup/ ) –

+2

歡迎來到Stackoverflow,[詢問好問題](http://www.catb.org/~esr/faqs/smart-questions.html)是一個學習過程。不要要求別人做你的工作。相反,要善意地嘗試自己解決問題,然後指出你有困難的地方。如果你不知道從哪裏開始,詢問你的教授或者閱讀教程是更好的選擇。 – MikeJRamsey56

+1

[使用Python從HTML文件中提取文本]的可能重複(http://stackoverflow.com/questions/328356/extracting-text-from-html-file-using-python) –

回答

1

什麼你正在試圖做的就是所謂的網絡爬行。 您可以使用lxml庫來解析html並獲得結果。

lxml的安裝目錄說明:http://lxml.de/installation.html

的例子,列出計算器主頁的問題:

import requests 
from lxml.etree import HTML 

host = 'http://stackoverflow.com/' 

resp = requests.get(host) 

tree = HTML(resp.text) 

questions = tree.xpath('.//a[@class="question-hyperlink"]') 

for question in questions: 
    print(question.text) 
相關問題