bs4とurllibを用いてスクレイピングをして以下のような構造のサイトからテキストを保存したいです。
スクレイピングしたいサイトHTML
… <p data-v-xxxx(任意の英数字列) class="yyyy(任意の英数字列)"> "持ってきたいテキスト" <!----> </p>
試したこと
以下のコードを実行しました。
該当のソースコード
Python
1from bs4 import BeautifulSoup 2import requests 3 4load_url = "https://jarujaru.com/" 5html = requests.get(load_url) 6soup = BeautifulSoup(html.content, "html.parser") 7topic = soup.find(class_="title") 8 9for element in topic.find_all('p'): 10 print(element.text)
上記の結果は以下です。
Traceback (most recent call last):
File "scjaru.py", line 9, in <module>
for element in topic.find_all('p'):
AttributeError: 'NoneType' object has no attribute 'find_all'