【发布时间】:2021-12-15 13:58:30
【问题描述】:
我一次只需要从列表中选择一定数量的(随机)关键字,而不是像现在这样使用所有键进行 API 调用。 我该如何继续?
# Search keywords definition
keywords = ["Televisori", "Notebook", "Tablet", "Apple", "Samsung", "Smartwatch", "Auricolari Bluetooth", "Fotocamera",
"Videocamera"]
# run bot function
def run_bot(bot, keywords):
# shuffling keywords list
random.shuffle(keywords)
# start loop
while True:
try:
items_full = []
# iterate over keywords
for el in keywords:
# iterate over pages
for i in range(1, 10):
items = search_items(el, CATEGORY, item_page=i)
# api time limit for another http request is 1 second
time.sleep(1)
items_full.append(items)
# concatenate all results
items_full = list(chain(*items_full))
【问题讨论】: