2016-07-18 39 views
0

我要趕在這個頁面的主題的各個環節:https://www.inforge.net/xi/forums/liste-proxy.1118/創建一個腳本來捕獲與Python網頁上的鏈接3

我試圖用這個腳本:

import urllib.request 
from bs4 import BeautifulSoup 

url = (urllib.request.urlopen("https://www.inforge.net/xi/forums/liste-proxy.1118/")) 
soup = BeautifulSoup(url, "lxml") 

for link in soup.find_all('a'): 
    print(link.get('href')) 

但它會打印頁面的所有鏈接,而不僅僅是我想要的主題鏈接。你能建議我做到這一點嗎?我還是個新手,最近我開始學習python。

回答

2

您可以使用BeautifulSoup解析HTML:

from bs4 import BeautifulSoup 
from urllib2 import urlopen 

url= 'https://www.inforge.net/xi/forums/liste-proxy.1118/' 
soup= BeautifulSoup(urlopen(url)) 

然後找到鏈接與

soup.find_all('a', {'class':'PreviewTooltip'}) 
+0

感謝的答案,但如果我按照你的方法,我打印(湯),它給了我頁面的來源,而不是主題的鏈接:\ – Sperly1987

+1

這會爲您提供標記對象。要將url作爲字符串,請在soup.find_all('a',{'class':'PreviewTooltip'})'' –

+0

'中使用'[tag.get('href')作爲標記。現在我得到了我想要的鏈接,但它們在html代碼中。 '[DICHVUSOCKS.US] 23h10 PM UPDATE 24/24- Good Socks'但它是一個很好的一步! :) – Sperly1987

相關問題