2024-06-09 01:35:52 +00:00
|
|
|
import argparse
|
|
|
|
import config
|
2024-06-12 02:17:37 +00:00
|
|
|
from tools.utils import str2bool
|
2024-06-09 01:35:52 +00:00
|
|
|
|
2024-06-11 15:55:42 +00:00
|
|
|
|
2024-06-09 01:35:52 +00:00
|
|
|
async def parse_cmd():
|
|
|
|
# 读取command arg
|
|
|
|
parser = argparse.ArgumentParser(description='Media crawler program.')
|
|
|
|
parser.add_argument('--platform', type=str, help='Media platform select (xhs | dy | ks | bili | wb)',
|
2024-06-11 15:55:42 +00:00
|
|
|
choices=["xhs", "dy", "ks", "bili", "wb"], default=config.PLATFORM)
|
2024-06-09 01:35:52 +00:00
|
|
|
parser.add_argument('--lt', type=str, help='Login type (qrcode | phone | cookie)',
|
2024-06-11 15:55:42 +00:00
|
|
|
choices=["qrcode", "phone", "cookie"], default=config.LOGIN_TYPE)
|
2024-06-09 01:35:52 +00:00
|
|
|
parser.add_argument('--type', type=str, help='crawler type (search | detail | creator)',
|
2024-06-11 15:55:42 +00:00
|
|
|
choices=["search", "detail", "creator"], default=config.CRAWLER_TYPE)
|
2024-06-09 01:35:52 +00:00
|
|
|
parser.add_argument('--start', type=int,
|
2024-06-11 15:55:42 +00:00
|
|
|
help='number of start page', default=config.START_PAGE)
|
2024-06-09 01:35:52 +00:00
|
|
|
parser.add_argument('--keywords', type=str,
|
2024-06-11 15:55:42 +00:00
|
|
|
help='please input keywords', default=config.KEYWORDS)
|
2024-06-12 02:17:37 +00:00
|
|
|
parser.add_argument('--get_comment', type=str2bool,
|
|
|
|
help='''whether to crawl level one comment, supported values case insensitive ('yes', 'true', 't', 'y', '1', 'no', 'false', 'f', 'n', '0')''', default=config.ENABLE_GET_COMMENTS)
|
|
|
|
parser.add_argument('--get_sub_comment', type=str2bool,
|
|
|
|
help=''''whether to crawl level two comment, supported values case insensitive ('yes', 'true', 't', 'y', '1', 'no', 'false', 'f', 'n', '0')''', default=config.ENABLE_GET_SUB_COMMENTS)
|
|
|
|
parser.add_argument('--save_data_option', type=str,
|
|
|
|
help='where to save the data (csv or db or json)', choices=['csv', 'db', 'json'], default=config.SAVE_DATA_OPTION)
|
|
|
|
parser.add_argument('--cookies', type=str,
|
|
|
|
help='cookies used for cookie login type', default=config.COOKIES)
|
2024-06-09 01:35:52 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# override config
|
|
|
|
config.PLATFORM = args.platform
|
|
|
|
config.LOGIN_TYPE = args.lt
|
|
|
|
config.CRAWLER_TYPE = args.type
|
|
|
|
config.START_PAGE = args.start
|
|
|
|
config.KEYWORDS = args.keywords
|
2024-06-12 02:17:37 +00:00
|
|
|
config.ENABLE_GET_COMMENTS = args.get_comment
|
|
|
|
config.ENABLE_GET_SUB_COMMENTS = args.get_sub_comment
|
|
|
|
config.SAVE_DATA_OPTION = args.save_data_option
|
|
|
|
config.COOKIES = args.cookies
|