###前提・実現したいこと
この動画を参考に指定したサイトに行き各見出しリンクで使われているそれぞれの単語の頻度を表示する関数を作りたい。
###発生している問題・エラーメッセージ
Traceback (most recent call last): File "word_frequency_counter.py", line 18, in <module> start("https://www.thenewboston.com/forum/") File "word_frequency_counter.py", line 9, in start soup = BeautifulSoup(source_code) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/__init__.py", line 168, in __init__ self._feed() File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/__init__.py", line 181, in _feed self.builder.feed(self.markup) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/bs4/builder/_lxml.py", line 61, in feed self.parser.feed(markup) File "parser.pxi", line 1201, in lxml.etree._FeedParser.feed (src/lxml/lxml.etree.c:102246) File "parser.pxi", line 1236, in lxml.etree._FeedParser.feed (src/lxml/lxml.etree.c:101171) lxml.etree.ParserError: Unicode parsing is not supported on this platform
エラーの内容をはっきりと理解できていないのですが、lxml.etree.ParserError: Unicode parsing is not supported on this platform
から察するにこれは単にbeautifulsoupとpython3の互換性の問題なのでしょうか?それとも原因は他にあるのでしょうか?
###ソースコード
動画で教えられている通りです。
word_frequency_counter.py
1import requests 2from bs4 import BeautifulSoup 3import operator 4 5 6def start(url): 7 word_list = [] 8 source_code = requests.get(url).text #gonna connect to the link and use it as plain text 9 soup = BeautifulSoup(source_code) 10 for post_text in soup.findAll('a', {'class': 'title text-semibold'}): #go through all the contents 11 content = post_text.string #.string = only get the texts thats inside "soup" 12 words = cotent.lower().split() 13 for each_word in words: 14 print(each_word) 15 word_list.append(each_word) 16 17 18start("https://www.thenewboston.com/forum/")
###補足情報(言語/FW/ツール等のバージョンなど)
Python3.4
Beautiful4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。