現在、Pythonで全ページの会社名を取得したいと思っているのですが、Printで行っても、エラー文も表示されずうまく行っているかと思うのですが、処理が実行されずに困っています。
ご教示いただけますと幸いでございます。
【行いたい内容】
ページ内の紹介写真に記載されている「〇〇株式会社」を”全ページ”スクレイピングしたいと考えています。
1ページだけなら取得はできるのですが、for文で、次のページ→「〇〇株式会社」全取得→次のページ→「〇〇株式会社」全取得・・・として取得をしたいです。
data_col = ["information1", "information2"] while True: res = requests.get('https://onlystory.co.jp/stories/?order=new') res.raise_for_status() html = BeautifulSoup(res.text, 'lxml') detail_url_list = html.find_all("company-name-s company-edit-hidden") next_page = html.find("next") for i in range(len(detail_url_list)): res2 = requests.get(urljoin(base_url, detail_url_list[i].a.get("href"))) res2.raise_for_status() html2 = BeautifulSoup(res2.text, 'lxml') information1 = html2.img.get("name") information2 = html2.a.get("href") s = pd.Series([information1, information2], index=data_col) df = df.append(s, ignore_index=True) df.to_csv(save_csv) time.sleep(5) if bool(next_page) == False: break dynamic_url = urljoin(base_url, next_page.a.get("href")) time.sleep(5)
回答1件
あなたの回答
tips
プレビュー