1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

石川県の Go To EATの加盟店舗のPDFをCSVに変換

Last updated at Posted at 2020-10-11

石川県 Go To Eat キャンペーンの加盟店舗のPDFをCSVに変換

10/28現在PDFがダウンロードできません

pip install tabula-py
pip install pandas
pip install beautifulsoup4
pip install requests
from urllib.parse import urljoin

import requests
from bs4 import BeautifulSoup

import pandas as pd
from tabula import read_pdf

url = "https://ishikawa-gotoeat-cpn.com/member_store/"

r = requests.get(url)
r.raise_for_status()

soup = BeautifulSoup(r.content, "html.parser")

dfs = [
    tbl
    for tag in soup.select("p.btn.btn_red.btn_pdf > a")
    for tbl in read_pdf(urljoin(url, tag.get("href")), pages="all", lattice=True)
]

df = pd.concat(dfs).set_axis(["市町村名", "店舗名"], axis=1).reset_index(drop=True)

df.to_csv("ishikawa.csv", encoding="utf_8_sig")
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?