如何将多行字符串拆分为数组

时间:2012-11-09 11:22:18

标签: python parsing beautifulsoup

我使用此代码:

from bs4 import BeautifulSoup

parser = BeautifulSoup(remote_data)
parse_data = parser.find_all('a')
for atag_data in parse_data:
    URL_list = atag_data.get('href')

当我尝试将URL_list拆分为数组时:

array = str.split(URL_list)

我给这3个数组:

['index1.html']
['example.exe']
['document.doc']

但我只需要一个数组:

['index1.html','example.exe','document.doc']

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

你没有得到一个数组 - 它是一个列表! 此外,您应该避免命名像builtins这样的变量。

关于你的问题:

from bs4 import BeautifulSoup
parser = BeautifulSoup(remote_data)
link_list = [a['href'] for a in parser.find_all('a')]
相关问题