dead-cells-wiki/data/patch/31-4/outfits.py

35 lines
1,010 B
Python
Raw Normal View History

2022-10-16 10:52:02 +08:00
import scrapy
import sys
import requests
import io
2022-10-16 11:18:23 +08:00
sys.path.append("../../convert/31-4")
2022-10-16 10:52:02 +08:00
from db import *
2022-10-16 11:18:23 +08:00
db.bind(provider="sqlite", filename="../../clean/31-4/data.sqlite3")
2022-10-16 10:52:02 +08:00
db.generate_mapping()
class OutfitSpider(scrapy.Spider):
name = "outfits"
start_urls = [
"https://deadcells.fandom.com/wiki/Outfits",
]
def parse(self, response):
for quote in response.css(".wikitable tbody tr"):
name_en = quote.css("td:nth-child(2) > span:last-child::text").get()
if not name_en:
print(name_en)
continue
preview = quote.css(
"td:nth-child(6) > span:last-child a::attr('href')"
).get()
try:
r = requests.get(preview)
with db_session:
w = Outfit.select(name_en=name_en).first()
w.preview = io.BytesIO(r.content).getbuffer().tobytes()
except:
print("Preview not available.")