Skip to content

Instantly share code, notes, and snippets.

@zyouyowa
Created January 29, 2023 06:41
Show Gist options
  • Save zyouyowa/40f33e0fc074f7238ebd38c1462a0b54 to your computer and use it in GitHub Desktop.
Save zyouyowa/40f33e0fc074f7238ebd38c1462a0b54 to your computer and use it in GitHub Desktop.
デッキのurlからカード名と枚数を取得してcsv形式で出力するやつ
#!python3
from bs4 import BeautifulSoup
import requests
import sys
# Usage:
# $ python3 deck2csv.py <url>
def main():
url = sys.argv[1]
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
cardtags = soup.find_all('tr', class_="row")
for el in cardtags:
name = el.contents[5].text.replace("\n", "")
num = el.contents[7].text.replace("\n", "").replace("\t", "")
print(name, num, sep=',')
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment