python3.6
1from bs4 import BeautifulSoup 2 3html = """ 4<html><body> 5 <h1>スクレイピングとは?</h1> 6 <p>webページを解析すること。</p> 7 <p>任意の箇所を抽出すること。</p> 8</body></html> 9""" 10 11 12soup = BeautifulSoup(html, 'html.parser') 13 14h1 = soup.html.body.h1 15p1 = soup.html.body.p 16p2 = p1.next_sibling.next_sibling 17 18 19print("h1 = " + h1.string) 20print("p = " + p1.string) 21print("p = " + p2.string)
これを実行すると
Traceback (most recent call last):
File "tarako2.py", line 1, in <module>
from BeautifulSoup4 import BeautifulSoup
ImportError: No module named 'BeautifulSoup4'
と表示されできません。
あと
pip3 install beautifulsoup4
をすると
Requirement already satisfied: beautifulsoup4 in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
と表示されます。
改善点を教えてください。

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/07 09:39