お世話になっております。下記の環境で
・Windows10-WSL ・Ubuntu18.04 ・python3.6.8
以下のコードを実行いたしました
import requests from bs4 import BeautifulSoup # スクレイピング対象の URL にリクエストを送り HTML を取得する res = requests.get('http://ooooooo.com/') # レスポンスの HTML から BeautifulSoup オブジェクトを作る soup = BeautifulSoup(res.text, 'html.parser') # ページに含まれるリンクを全て取得する links = [url.get('href') for url in soup.find_all('a')] print(links)
結果はこの通りです
Traceback (most recent call last): File "html.py", line 2, in <module> from bs4 import BeautifulSoup File "/home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages/bs4/__init__.py", line 31, in <module> from .builder import builder_registry, ParserRejectedMarkup File "/home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages/bs4/builder/__init__.py", line 7, in <module> from bs4.element import ( File "/home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages/bs4/element.py", line 19, in <module> from bs4.formatter import ( File "/home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages/bs4/formatter.py", line 1, in <module> from bs4.dammit import EntitySubstitution File "/home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages/bs4/dammit.py", line 13, in <module> from html.entities import codepoint2name File "/mnt/c/Users/shinya.kutsukake/public_html/python/html.py", line 2, in <module> from bs4 import BeautifulSoup ImportError: cannot import name 'BeautifulSoup'
pip install beautifulsoup4
は既に実行してあり
Requirement already satisfied: beautifulsoup4 in /home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages (4.8.2) Requirement already satisfied: soupsieve>=1.2 in /home/kutu/.pyenv/versions/3.6.8/lib/python3.6/site-packages (from beautifulsoup4) (2.0)
となり、
pip install beautifulsoup
は
Collecting beautifulsoup Using cached BeautifulSoup-3.2.2.tar.gz (32 kB) ERROR: Command errored out with exit status 1: command: /home/kutu/.pyenv/versions/3.6.8/bin/python3.6 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-dkg1gbs9/beautifulsoup/setup.py'"'"'; __file__='"'"'/tmp/pip-install-dkg1gbs9/beautifulsoup/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-dkg1gbs9/beautifulsoup/pip-egg-info cwd: /tmp/pip-install-dkg1gbs9/beautifulsoup/ Complete output (6 lines): Traceback (most recent call last): File "<string>", line 1, in <module> File "/tmp/pip-install-dkg1gbs9/beautifulsoup/setup.py", line 3 "You're trying to run a very old release of Beautiful Soup under Python 3. This will not work."<>"Please use Beautiful Soup 4, available through the pip package 'beautifulsoup4'." ^ SyntaxError: invalid syntax ---------------------------------------- ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
となります。
おわかりになる方いらっしゃいましたらよろしくお願いします
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。