【发布时间】:2019-07-10 07:19:54
【问题描述】:
大家好,我目前正在尝试从 url 获取一些数据,然后尝试预测该文章应该属于哪个类别。 到目前为止,我已经这样做了,但它有一个错误:
info = pd.read_csv('labeled_urls.tsv',sep='\t',header=None)
html, category = [], []
for i in info.index:
response = requests.get(info.iloc[i,0])
soup = BeautifulSoup(response.text, 'html.parser')
html.append([re.sub(r'<.*?>','',
str(soup.findAll(['p','h1','\href="/avtorji/'])))])
category.append(info.iloc[0,i])
data = pd.DataFrame()
data['html'] = html
data['category'] = category
错误是这样的:
IndexError: 单个位置索引器超出范围。
有人可以帮帮我吗?
【问题讨论】:
标签: python python-3.x pandas web-scraping