【发布时间】:2017-12-02 17:25:35
【问题描述】:
我正在尝试编写一些代码来抓取网站以获取链接列表,然后我将对其进行其他操作。我发现了一些代码here,我正在尝试对其进行调整,以便将其添加到系列中,而不是打印列表。我的代码如下:
import pandas as pd
from bs4 import BeautifulSoup
from urllib.parse import urljoin
user_agent = {'User-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0'}
linksList = pd.Series()
def process(url):
r = requests.get(url, headers=user_agent)
soup = BeautifulSoup(r.text, "lxml")
for tag in soup.findAll('a', href=True):
tag['href'] = urljoin(url, tag['href'])
linksList.append(tag['href'])
当我传递一个 URL 时,我收到以下错误
cannot concatenate a non-NDFrame object
知道我哪里出错了吗?
【问题讨论】:
标签: python pandas beautifulsoup