У меня есть бот python, который ищет данные на веб-сайте. Как только он получает данные, он фильтруется, и имена читаются четко; это список 1. Затем в списке 2 у меня есть строки с именами наборов, и я пытаюсь сравнить список 2 со списком 1, чтобы увидеть, содержит ли список 1 одну из строк из списка 2, и если это так, В список 1 будет вставлена строка, показывающая, что он содержит строку из списка 2. Это мой l oop:
for x in boss_bots:
for index, y in enumerate(new_bots):
if x in y[index]:
new_bots.insert(index, 'Boss Bot')
Вот остальной код
from selenium import webdriver
from time import sleep
boss_bots = ['Flunky', 'Pencil Pusher', 'Yesman', 'Micro manager', 'Downsizer', 'Head Hunter', 'Corporate Raider',
'The Big Cheese']
cash_bots = ['Short Change', 'Penny Pincher', 'Tightwad', 'Bean Counter', 'Number Cruncher', 'Money Bags', 'Loan Shark',
'Robber Baron']
sell_bots = ['Cold Caller', 'Telemarketer', 'Name Dropper', 'Glad Hander', 'Mover & Shaker', 'Two-Face', 'The Mingler',
'Mr. Hollywood']
law_bots = ['Bottom Feeder', 'Blood sucker', 'Double Talker', 'Ambulance Chaser', 'Back Stabber', 'Spin Doctor',
'Legal Eagle', 'Big Wig']
def format_box(bots):
new_bots = []
for string in bots:
new_bot = string.replace('', ' ')
new_bots.append(new_bot)
return new_bots
def print_bots(bots):
for i in bots:
print(i)
print()
def get_all_info():
driver = webdriver.Chrome()
driver.get("https://toonhq.org/invasions/")
sleep(2)
bots = driver.find_elements_by_class_name('media-body')
info = [name.text for name in bots if name.text != '']
new_bots = format_box(info)
t = 0
""" for index, (x, y) in enumerate(zip(boss_bots, info)):
if x == y:
new_bots.insert(index, 'Boss Bot')"""
for x in boss_bots:
for index, y in enumerate(new_bots):
#print('Boss bots: ' + x + 'index: ' + str(index) + 'Bot list: ' + y)
if x in y[index]:
new_bots.insert(index, 'Boss Bot')
print_bots(new_bots)
driver.close()
return info
get_all_info()