Windows10環境で、Python3.7 IDLEにて以下を実行しました。
Python3
1import urllib.request 2from bs4 import BeautifulSoup 3 4class Scraper: 5 def __init__(self, site): 6 self.site = site 7 8 9 def scrape(self): 10 r = urllib.request.urlopen(self.site) 11 html = r.read() 12 parser = "html.parser" 13 sp = BeautifulSoup(html, parser) 14 for tag in sp.find_all("a"): 15 url = tag.get("href") 16 if url is None: 17 continue 18 if "html" in url: 19 print("\n" + url) 20 21news = "https://news.google.com/" 22Scraper(news).scrape()
すると何の結果も出力されませんでした。
ライブラリのインストールがうまく行ってないのかと思い以下のみを実行するとエラーは表示されませんでした。
Python
1import urllib.request 2from bs4 import BeautifulSoup
Python3.7 IDLEの設定が悪いのかと以下を試してみましたが、ふつうに出力されました。
Python3
1Print("1") 2>>> 1
どこがおかしいのか、教えてください。
よろしくおねがいします。
追記:
ご回答ありがとうございました。
一部変更してみましたが、今度はエラーが出てしまいました。
モジュールが足りない、という意味なのでしょうか...
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/03/13 00:22
2019/03/13 00:27