我正在嘗試使用strip()來刪除某些HTML的結尾。我們的想法是,最終建設成一個圈這一點,但現在我只是想弄清楚如何使這項工作:Python字符串條
httpKey=("<a href=\"http://www.uaf.edu/academics/degreeprograms/index.html>Degree Programs</a>")
httpKeyEnd=">"
#the number in the httpKey that the httpKey end is at
stripNumber=(httpKey.find(httpKeyEnd))
#This is where I am trying to strip the rest of the information that I do not need.
httpKey.strip(httpKey.find(httpKeyEnd))
print (httpKey)
最終的結果是打印httpKey只篩選:
A HREF =「http://www.uaf.edu/academics/degreeprograms/index.html
您的最終目標是什麼?你是否試圖提取href?如果是這樣,通過使用像[美麗的湯](http://www.crummy.com/software/BeautifulSoup/)的HTML解析庫,你的生活會變得更加容易。 – senshin 2014-11-02 06:57:48
是的,那是目標。然而,這是我正在做的一項家庭作業任務,只能使用字符串操作。 – akagent49 2014-11-02 06:59:34
好的,接下來的問題是:故意在href之後沒有關閉引號,還是一個錯字? – senshin 2014-11-02 07:01:29