0

仮想環境にてPythonでのスクレイピングの勉強をしています。参考にしているのは「Pythonクローリング&スクレイピング」です。

コードをそのまま写して実行しているのですが結果が出力されません。エラーは出ずに通っているのでコードに問題は無いと思いますが、何も出力されないのはなぜでしょうか。以前質問させていただいた時の修正点は改善できているので全く解決策がわからず困っています。

from typing import Iterator
import requests
import lxml.html

def main():
  response = requests.get('https://gihyo.jp/dp')
  urls = scrape_list_page(response)
  for url in urls:
    print(url)

def scrape_list_page(response: requests.Response) -> Iterator[str]:
  html = lxml.html.fromstring(response.text)
  html.make_links_absolute(response.url)
  for a in html.cssselect('#listBook > li > a[itemprop="url"]'):
    url = a.get('href')
    yield url

if __name__ == '__name__':
  main()

本来ならば以下の行に続けてURLが表示されるようです。よろしくお願いいたします。

(scraping) vagrant@ubuntu-bionic:/vagrant$ python python_crawler_2.py
2

0

この質問に回答するには、ログインする必要があります。

のタグが付いた他の質問を参照する。