将网址保存到列表中

时间:2014-10-24 08:17:22

标签: list url beautifulsoup

我想列出一个我从网页上获得的网址列表,我知道这很简单,但我无法理解它(自昨天午餐以来一直很头疼!)

无论如何,这是我的代码

from bs4 import BeautifulSoup
from urllib import request
webpage = request.urlopen("http://www.dsfire.gov.uk/News/Newsdesk/IncidentsPast7days.cfm?siteCategoryId=3&T1ID=26&T2ID=35")
soup = BeautifulSoup(webpage)
incidents = soup.find(id="CollapsiblePanel1")
for line in incidents.find_all('a'):
            link = line.get('href')
            Links = Links + Link

我知道它不起作用,但我不知道如何制作它大声抱歉并提前致谢!

RAIF

1 个答案:

答案 0 :(得分:0)

改变这个:

for line in incidents.find_all('a'):
    link = line.get('href')
    Links = Links + Link

对此:

Links = []
for line in incidents.find_all('a'):
    Links.append(line.get('href'))