Very new to python and struggling with this loop. I'm trying to pull the html attribute data address from a list of static pages that i already have in list format. I've managed to use BS4 to pull the data from one page but I cannot get the loop correct to iterate through my list of URLs. Right now I am receiving this error (Invalid URL '0': No schema supplied. Perhaps you meant http://0?) but I checked the URLs in single pulls and they all work. Here is my working single pull code:
import requests
from bs4 import BeautifulSoup
result = requests.get('https://www.coingecko.com/en/coins/0xcharts')
src = result.content
soup = BeautifulSoup(src, 'lxml')
contract_address = soup.find(
'i', attrs={'data-title': 'Click to copy'})
print(contract_address.attrs['data-address'])
This is the loop I am working on:
import requests
from bs4 import BeautifulSoup
url_list = ['https://www.coingecko.com/en/coins/2goshi','https://www.coingecko.com/en/coins/0xcharts']
for link in range(len(url_list)):
result = requests.get(link)
src = result.content
soup = BeautifulSoup(src, 'lxml')
contract_address = soup.find(
'i', attrs={'data-title': 'Click to copy'})
print(contract_address.attrs['data-address'])
url_list.seek(0)