2016-07-18 42 views
3

感謝本次論壇的幫助下,我終於到達了此python3代碼:告訴蟒蛇在每行寫的東西

import urllib.request 
from bs4 import BeautifulSoup 

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

for tag in soup.find_all('a', {'class':'PreviewTooltip'}): 
    links = (tag.get('href')) 
    print (links) 

它在打印網頁主題的各個環節:https://www.inforge.net/xi/forums/liste-proxy.1118/ 但我需要的最後一件事是:如何告訴python每一行寫廣告,首先是「線程」字,鏈接的另一部分? (https://www.inforge.net/xi/) 在此先感謝!

+0

表明我們至少... – Netwave

回答

4

你只需要concatenate與每個鏈接的基地網址。

試試這個代碼:

import urllib.request 
from bs4 import BeautifulSoup 

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

base = 'https://www.inforge.net/xi/' 

for tag in soup.find_all('a', {'class':'PreviewTooltip'}): 
    links = (tag.get('href')) 
    full_url = base + links 
    print (full_url) 

輸出:

https://www.inforge.net/xi/threads/dichvusocks-us-23h10-pm-update-24-24-good-socks.455661/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-11h11-pm.455660/ https://www.inforge.net/xi/threads/dichvusocks-us-22h10-pm-update-24-24-good-socks.455656/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-9h45-pm.455655/ https://www.inforge.net/xi/threads/dichvusocks-us-18h30-pm-update-24-24-good-socks.455651/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-6h25-pm.455650/ https://www.inforge.net/xi/threads/dichvusocks-us-13h00-pm-update-24-24-good-socks.455634/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-1h00-pm.455633/ https://www.inforge.net/xi/threads/dichvusocks-us-09h15-am-update-24-24-good-socks.455631/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-8h00-am.455627/ https://www.inforge.net/xi/threads/dichvusocks-us-01h35-am-update-24-24-good-socks.455614/ https://www.inforge.net/xi/threads/dichvusocks-us-23h10-pm-update-24-24-good-socks.455610/ https://www.inforge.net/xi/threads/dichvusocks-us-20h15-pm-update-24-24-good-socks.455601/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-8h00-pm.455596/ https://www.inforge.net/xi/threads/dichvusocks-us-15h10-pm-update-24-24-good-socks.455588/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-1h25-pm.455587/ https://www.inforge.net/xi/threads/dichvusocks-us-10h45-am-update-24-24-good-socks.455585/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-10h40-am.455584/ https://www.inforge.net/xi/threads/vn5socks-net-auto-update-24-7-good-socks-7h30-am.455583/ https://www.inforge.net/xi/threads/dichvusocks-us-01h40-am-update-24-24-good-socks.455569/

+0

哦...我很愚蠢的預期輸出!儘管如此,如果我已經做到了,它只會添加到第一行......但這很容易......謝謝! – Sperly1987