題名の通り、pythonのコードを実行するとエラーが出ます。
環境;python2系
Google app engine cloud shell
コード
python
1# coding: UTF-8 2import urllib2 3from bs4 import BeautifulSoup 4 5# アクセスするURL 6url = "http://www.nikkei.com/" 7 8# URLにアクセスする htmlが帰ってくる → <html><head><title>経済、株価、ビジネス、政治のニュース:日経電子版</title></head><body.... 9html = urllib2.urlopen(url) 10 11# htmlをBeautifulSoupで扱う 12soup = BeautifulSoup(html, "html.parser") 13 14# タイトル要素を取得する → <title>経済、株価、ビジネス、政治のニュース:日経電子版</title> 15title_tag = soup.title 16 17# 要素の文字列を取得する → 経済、株価、ビジネス、政治のニュース:日経電子版 18title = title_tag.string 19 20# タイトル要素を出力 21print title_tag 22 23# タイトルを文字列を出力 24print title 25
(Qiitaからそのままコピペしました)
出力
>>username@aerial-summit-189320:~/src$ python test.py Traceback (most recent call last): File "test.py", line 3, in <module> from ba4 import BeautifulSoup ImportError: No module named ba4
その後 beutifulsoup をもう一度インストールしたうえ、実行しましたが、結果は変わりませんでした。
>>username@aerial-summit-189320:~/src$ pip install -t libs beautifulsoup Collecting beautifulsoup Installing collected packages: beautifulsoup Successfully installed beautifulsoup-3.2.1 Target directory /home/username/src/libs/BeautifulSoup.py already exists. Specify --upgrade to force replacement. Target directory /home/username/src/libs/BeautifulSoup-3.2.1.dist-info already exists. Specify --upgrade to force replacement. Target directory /home/username/src/libs/BeautifulSoupTests.pyc already exists. Specify --upgrade to force replacement. Target directory /home/username/src/libs/BeautifulSoupTests.py already exists. Specify --upgrade to force replacement. Target directory /home/username/src/libs/BeautifulSoup.pyc already exists. Specify --upgrade to force replacement.
なにが原因と考えられるでしょうか?
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。