このエラーの対処が分からず、困っています。
教えて欲しいです。
【エラー】
0%| | 0/2 [00:00<?, ?it/s]0
0%| | 0/2 [00:06<?, ?it/s]
---------------------------------------------------------------------------
LookupError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/sumy/nlp/tokenizers.py in _get_sentence_tokenizer(self, language)
126 path = to_string("tokenizers/punkt/%s.pickle") % to_string(language)
--> 127 return nltk.data.load(path)
128 except (LookupError, zipfile.BadZipfile) as e:
5 frames
LookupError:
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('punkt')
Searched in:
- '/root/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/usr/nltk_data'
- '/usr/lib/nltk_data'
- ''
**********************************************************************
During handling of the above exception, another exception occurred:
LookupError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/sumy/nlp/tokenizers.py in _get_sentence_tokenizer(self, language)
130 "NLTK tokenizers are missing or the language is not supported.\n"
131 """Download them by following command: python -c "import nltk; nltk.download('punkt')"\n"""
--> 132 "Original error was:\n" + str(e)
133 )
134
LookupError: NLTK tokenizers are missing or the language is not supported.
Download them by following command: python -c "import nltk; nltk.download('punkt')"
Original error was:
**********************************************************************
Resource punkt not found.
Please use the NLTK Downloader to obtain the resource:
>>> import nltk
>>> nltk.download('punkt')
Searched in:
- '/root/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- '/usr/nltk_data'
- '/usr/lib/nltk_data'
- ''
**********************************************************************
【コード】
#@title
import requests
import json
import csv
import pytz
import datetime
import tqdm
import numpy as np
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from time import sleep
from google.colab import files
##############
### DEFINE ###
##############
#KEYWORD = "福祉"
#SLEEP_TIME = 0.5
url = 'https://api.jgrants-portal.go.jp/exp/v1/public/subsidies?keyword=' + keyword + '&sort=created_date&order=DESC&acceptance=1'
req = requests.get(url)
reqJSON = json.loads(req.text)
# resultデータのループ
csvList = []
ID = []
for i in tqdm.tqdm(range(len(reqJSON["result"]))):
# tqdm
np.pi*np.pi
if i % 1e6 == 0:
print(i)
# csv書き込み用リストにヘッダー行を追加
resultData=reqJSON["result"][i]
csvRow = []
csvRow.append(resultData["title"])
csvRow.append(resultData["id"])
csvRow.append(resultData["acceptance_start_datetime"])
csvRow.append(resultData["acceptance_end_datetime"])
csvRow.append(resultData["subsidy_max_limit"])
csvRow.append(resultData["target_area_search"])
csvRow.append(resultData["target_number_of_employees"])
# selenium,Chromedriverの定義
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',options=options)
# IDに格納したIDリストをもとにHPを開けてスクレイピング
tURL = "https://www.jgrants-portal.go.jp/subsidy/" + resultData["id"]
wd.get(tURL)
sleep(sleep_time)
detail = wd.find_element(by=By.TAG_NAME, value="table").text
# Load Packages
from sumy.parsers.plaintext import PlaintextParser
from sumy.nlp.tokenizers import Tokenizer
# For Strings
parser = PlaintextParser.from_string(detail,Tokenizer("english"))
from sumy.summarizers.text_rank import TextRankSummarizer
# Summarize using sumy TextRank
summarizer = TextRankSummarizer()
summary =summarizer_4(parser.document,2)
text_summary=""
for sentence in summary:
text_summary+=str(sentence)
print(text_summary)
# csv書き込み用リストに詳細を追加
csvRow.append(detail)
csvRow.append(text_summary)
# tURLを追加
csvRow.append(tURL)
# 1行を1要素として配列に保存
csvList.append(csvRow)
wd.close()
# 新規CSVファイルの作成
csv_date = datetime.datetime.now(pytz.timezone('Asia/Tokyo')).strftime("%Y%m%d")
csv_file_name = ( keyword + "jGrants" + csv_date + ".csv")
f = open(csv_file_name, "w", encoding="Shift-jis", errors="ignore")#windowsの場合encoding=Shift-js
# csvファイルへの書き込み
writer = csv.writer(f, lineterminator="\n")
csv_header = ["タイトル","ID","開始日","終了日","金額の上限","対象地域","対象となる従業員数","詳細","要約","URL"]
writer.writerow(csv_header)
for csvData in csvList:
writer.writerow(csvData)
f.close()
# csvファイル出力
files.download(csv_file_name)
python -c "import nltk; nltk.download('punkt')"
コマンドを実行してNLTK環境を構築すると、このエラー自体は解消しますか?