前提・実現したいこと
指定したURLからリンクを取得し、そのリンクから情報を取得する処理を実現するため試行錯誤をしております。指定のURLからのリンクの取得とリンク内の情報の取得を別々のファイルに書いて実行テストを行ったところ正常に動作しました。
それとループ処理のfor文の箇所も実行テストをし正常に動作していることを確認しています。
ただ色々試してみてfor文の一行箇所に関してエラーの表記がでます。
このコードに関してのエラーですがどういったことが災いして起きているのでしょうか...
発生している問題・エラーメッセージ
Traceback (most recent call last): File "base.py", line 11, in <module> html = urllib.request.urlopen(x) NameError: name 'urllib' is not defined
該当のソースコード
from bs4 import BeautifulSoup import urllib.request as req url = "https://xxxxxxxxxxxxxxxxxxxxxxxx" res = req.urlopen(url) soup = BeautifulSoup(res, 'html.parser') url_items = soup.select('a[href]') for x in url_items: html = urllib.request.urlopen(x) soup = BeautifulSoup(html, 'html.parser') title1 = soup.select('h1') print("h1 = ",title1) description = soup.select('#item_detail') print("item_detail = ",description) price1 = soup.select('#price') print("price = ",price1)
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/11 06:16
2018/06/11 06:24
2018/06/11 06:36
2018/06/11 06:38
2018/06/11 06:38
2018/06/11 06:41
2018/06/11 06:53
2018/06/11 06:59
2018/06/11 07:11
2018/06/11 07:14
2018/06/11 07:38