python初心者です
IDLEを使用して、スクレイピングを実行すると
Traceback (most recent call last):
File "/Users/user/Documents/test.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
こういったエラーが出ます
sudo pip3 install beautifulsoup4
sudo pip3 install bs4
で正常にこの二つはインストールされています
いろいろ調べてみたのですが、もしかするとインストールに使用したpythonと実行に使用しているpythonのversionが異なっているかもしれません。
その場合のpythonのversionを揃える方法が知りたいです。
言葉足らずかもしれないので、その際はご指摘ください。
import urllib.request from bs4 import BeautifulSoup class Scraper: def __init__(self,site): self.site = site def scrape(self): r = urllib.request.urlopen(self.site) html = r.read() parser = "html.perser" sp = BeautifulSoup(html,parser) for tag in sp.find_all("a"): url = tag.get("href") if url is None: continue if "html" in url: print("\n" + url) news = "https://news.google.com/" Scraper(news).scrape()
回答4件
あなたの回答
tips
プレビュー