¿Cómo puedo encontrar el nombre por el parámetro establecido?

¿Cómo puedo encontrar el nombre por el parámetro establecido?

Estoy tratando de escribir un programa que cree un enlace a la API. Para ello utilizo bs4, con el que busco el div que necesito, pero me da error porque el programa no funciona correctamente. Quiero encontrar solo este coin name que está en el coin list. ¿Cómo puedo arreglarlo? Por favor, dame una mano.

Mi código:

s = requests.Session()
response = s.get(url=url, headers=headers)

soup = BeautifulSoup(response.text, 'lxml')
page_list = int(soup.find_all('li', class_='page')[-1].text)

coin_api_list = []
coin_api_list_not_in_div = []
coins_list = ["Metis Token","TownCoin","JasmyCoin","SIDUS","Paribus","Qredo Token","SENATE","YAM","CircuitsOfValue","E-RADIX","Ross Ulbricht Genesis Collection","ParaSwap","CERE Network","Victoria VR","Boba Token","Ribbon","Gelato Network Token","decentral.games","ConstitutionDAO","Octopus Network Token","HEX","AtariToken","88mph.app","BOND","Yield","Juicebox","NAGA Coin","Lido DAO Token","Life Crypto","Anyswap","AnRKey X","MarsToken","Wrapped TONCoin", "MoonRabbit","LQTY","Boson Token","GP","PolkaBridge","VISOR","TRVL","Gold Fever Native Gold","DeFine Art","Clearpool","Vader","Cellframe Token","ARCx Governance Token","DAFI Token","UniBright","NFTrade Token","RAZOR","Quickswap","Skyrim Finance","Mimir Token","DAOstack","10Set Token","SAITO","Nectar","Deri","Olympus","Dogs Of Elon","VesperToken","Geeq","PYR Token","Nahmii","Biconomy Token","Student Coin","Creaticles","Polkamarkets","Spell Token","OnX.finance","Morpheus.Network","XY Token","Unit Protocol","Dusk Network","XDEFI","EQIFi Token","NUM Token","Coinweb","pTokens TLOS","ASSEMBLE","UniTrade","SPLYT SHOPX","GDT","XCAD Token","Synapse","Game Coin","YFLink","BTRST","Tiger King","SOS","Kishu Inu","TON Coin","DeRace Token","FLOKI","Saitama Inu","ImpactXP","HyperDao","MetaCat","VLaunch","Shiryo-Inu","Radio Caca V2","Strips Token","Merit Circle","Gas DAO","DotOracle","Eden","Pendle","Tempus","Gods Unchained","Phantasma Stake","Klever","BitDAO","MCDEX Token","Keanu Inu"]

for page in range(1, page_list + 1):

    r = requests.get(url = f'https://coinmarketcap.com/?page={page}', headers=headers)
    soup=BeautifulSoup(r.content, 'html.parser')

    find_coin_href = soup.findAll('div',class_='sc-16r8icm-0 escjiH')
    for coin_name in find_coin_href:
        coin_name = soup.findAll('p',class_='sc-1eb5slv-0 iworPT')
        for check_name in coin_name:
            check_name = check_name.text
            if check_name == coins_list:

                for links in find_coin_href:
                    for link in links.find_all('a',href=True):
                        main_link=baseurl+link['href']
                        coin_api_list.append(main_link)


    print(f'Processed {page}/{page_list}')

with open('apilinks2.text', 'w') as file:
    for url in coin_api_list + coin_api_list_not_in_div:
        name = (url.split('/')[-2])
        file.write(f'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/market-pairs/latest?slug={name}&start=1&limit=100&category=spot&sort=cmc_rank_advanced \n')
Mostrar la mejor respuesta

¿Cuáles son los url y headers a los que se hace referencia en la línea 2?

url='coinmarketcap.com' headers = { 'aceptar' : 'texto/html,aplicación/xhtml+xml,aplicación /xml;q=0.9,image‌​/avif,image/webp,ima‌​ge/apng,/;q=0.8,appl‌​ication/signed-excha‌​nge;v=b3;q =0.9', 'agente de usuario': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, como Gecko) Chrome/95.0.4638.69 Safari/537.36' }

Hay dos problemas con su código:

  1. Esto: if check_name == coins_list: siempre devolverá false, ya que check_name es una cadena y coins_list es una lista. Quieres if check_name in coins_list:.
  2. baseurl no está definido en el fragmento de código. Cámbielo a url.

Realice estos dos cambios y debería tener una salida no vacía en su archivo de texto. Las URL de este archivo parecen estar bien formadas.