Я хотел создать веб-сервис, который будет предоставлять сводку текстов по указанному URL с использованием python, beautifulsoup и nltk.
Однако я сталкиваюсь со следующей ошибкой в Azure ML Studio
Схемы в AZURE:
Модуль EnterData имеет URL из вики
Выполнить скрипт Python имеет следующий код
import pandas as pd
import urllib.request as ur
from bs4 import BeautifulSoup
def azureml_main(dataframe1="https://en.wikipedia.org/wiki/Fluid_mechanics", dataframe2 = None):
wiki = dataframe1[0].to_string()
page = ur.urlopen(wiki)
soup = BeautifulSoup(page)
df= pd.DataFrame([soup.find_all('p')[0].get_text()], columns =['article_text'])
return dataframe1,
Выполнение этого эксперимента приводит к следующей ошибке:
Error 0085: The following error occurred during script evaluation, please view the output log for more information:
---------- Start of error message from Python interpreter ----------
Caught exception while executing function: Traceback (most recent call last):
File "C:\pyhome\lib\site-packages\pandas\indexes\base.py", line 1876, in get_loc
return self._engine.get_loc(key)
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:4027)
File "pandas\index.pyx", line 157, in pandas.index.IndexEngine.get_loc (pandas\index.c:3891)
File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12408)
File "pandas\hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12359)
KeyError: 0
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\server\invokepy.py", line 199, in batch
odfs = mod.azureml_main(*idfs)
File "C:\temp\84d7e9fbcfe54596a2e7de022b4d236c.py", line 23, in azureml_main
wiki = dataframe1[0][0].to_string()
File "C:\pyhome\lib\site-packages\pandas\core\frame.py", line 1992, in __getitem__
return self._getitem_column(key)
File "C:\pyhome\lib\site-packages\pandas\core\frame.py", line 1999, in _getitem_column
return self._get_item_cache(key)
File "C:\pyhome\lib\site-packages\pandas\core\generic.py", line 1345, in _get_item_cache
values = self._data.get(item)
File "C:\pyhome\lib\site-packages\pandas\core\internals.py", line 3225, in get
loc = self.items.get_loc(item)
File "C:\pyhome\lib\site-packages\pandas\indexes\base.py", line 1878, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:4027)
File "pandas\index.pyx", line 157, in pandas.index.IndexEngine.get_loc (pandas\index.c:3891)
File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12408)
File "pandas\hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12359)
KeyError: 0
Process returned with non-zero exit code 1
---------- End of error message from Python interpreter ----------
Start time: UTC 11/11/2018 15:34:21
End time: UTC 11/11/2018 15:34:30
- Я использую Anaconda 4.0 / Python 3.5 для запуска этого фрагмента.
- когда я назначаю URL переменной wiki, код успешно запускается на моей локальной машине
- Я не уверен, почему я не могу получить значение из входного фрейма данных.
- Входной фрейм данных не имеет заголовка, поэтому dataframe1 [0] должен получать URL-адрес напрямую.
Спасибо, что помогли мне в этом.