87 lines
2.2 KiB
Python
87 lines
2.2 KiB
Python
from core import spiders, types
|
|
from utils import formats, messages
|
|
|
|
class SpiderModule(spiders.Spiders):
|
|
project_name = "example"
|
|
|
|
def __init__(self):
|
|
super().__init__(
|
|
self.project_name,
|
|
bitch = 10,
|
|
worker_num = 1,
|
|
switch_clash = False,
|
|
reflush_browser = False
|
|
)
|
|
|
|
def get_category_urls(self) -> list[str]:
|
|
category_urls = []
|
|
|
|
pass
|
|
|
|
return category_urls
|
|
|
|
def get_goods_urls(self, category_url: str) -> list[str]:
|
|
self.tab.get(f"{category_url}")
|
|
goods_urls = []
|
|
|
|
pass
|
|
|
|
return goods_urls
|
|
|
|
def get_goods_info(self, url) -> types.GoodsInfo:
|
|
def get_image_urls():
|
|
image_urls = []
|
|
pass
|
|
return image_urls
|
|
|
|
tab = self.browser.new_tab(url)
|
|
tab.set.window.max()
|
|
spu = formats.url_to_spu(url)
|
|
|
|
desc = "简介"
|
|
brand = "品牌"
|
|
title = "标题"
|
|
price = 0.00
|
|
old_price = price
|
|
|
|
main_images = get_image_urls()
|
|
|
|
goods_info = types.GoodsInfo(
|
|
title=title,
|
|
desc=desc,
|
|
brand=brand,
|
|
url=url,
|
|
spu=spu,
|
|
price=price,
|
|
old_price=old_price,
|
|
)
|
|
|
|
m_data = []
|
|
attr_items = []
|
|
|
|
if len(attr_items) == 0:
|
|
goods_info.attr = 'S'
|
|
goods_info.attr_items = []
|
|
goods_info.images = main_images
|
|
goods_info.p_lists = []
|
|
else:
|
|
goods_info.attr = 'M'
|
|
goods_info.attr_items = m_data
|
|
for attr_item in attr_items:
|
|
goods_info.p_lists.append(types.GoodsInfo.GoodsInfoP(
|
|
attr_items=attr_item['items'],
|
|
price=attr_item['price'],
|
|
old_price=attr_item['old_price'],
|
|
images=attr_item['images']
|
|
))
|
|
for image_url in attr_item['images']:
|
|
if image_url not in main_images:
|
|
main_images.append(image_url)
|
|
goods_info.images = main_images
|
|
|
|
try:
|
|
tab.close()
|
|
except:
|
|
pass
|
|
return goods_info
|