我想創建一個程序,從電視上映網站獲取html,然後使用拆分功能將所有html數據拆分爲只有頻道名稱和當前正在播放的節目一個表格,例如:BBC 1 - '節目名稱'。我只需要幫助我的第一次拆分功能後,如果任何人都可以幫助,將不勝感激。Python獲取網頁數據
import urllib2
import string
proxy = urllib2.ProxyHandler({"http" : "http://c99.cache.e2bn.org:8084"})
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
tvCatchup = urllib2.urlopen('http://www.TVcatchup.com')
html = tvCatchup.read()
firstSplit = html.split('<a class="enabled" href="/watch.html?c=')[1:]
for i in firstSplit:
print i
secondSplit = html.split ('1" title="BBC One"></a></li><li class="v-type" style="color:#6d6d6d;">')[1:]
for i in secondSplit:
print i
因爲這是學校工作,這是我使用這些的唯一原因,因爲它們是我們在操作網頁時被教導使用的。也只是爲了清楚的代理處理程序是這樣的程序可以在學校時通過代理實際訪問互聯網 – user1655562
我目前正在給你寫一個完整的代碼,請給我一分鐘:) – Goranek
好的,謝謝,它只是主要我很困惑的事情是如何創建一個列表的HTML,在列表上的itter和刪除其餘的HTML,這就是我不知道該怎麼做 – user1655562