Answer the question
In order to leave comments, you need to log in
How can I output a link that was found by coincidence?
I'm trying to write a program that will find coins by a given parameter (coins_list). But my program does not work correctly and finds coins with and without a parameter and displays them all, that is, it returns to the find_coin_href variable and does not take into account the condition: `if check_name in coins_list` How can I fix this? Please help me.
My code:
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 = []
coins_list = ["HEX"]
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 in coins_list:
for links in find_coin_href :
for link in links.findAll('a',href=True):
main_link=baseurl+link['href']
if main_link not in coin_api_list:
coin_api_list.append(main_link)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question