index (find) + len (find) ValueError: substring not found Crawler Python

2

Personal I need a help for code in Python looking for internet result.

  

Python 3.6

The first one of Bitcoin worked, the second one with error.

from urllib import request

url = request.urlopen("https://dolarhoje.com/bitcoin-hoje/").read()
url = str(url)
find = '<input type="text" id="nacional" value="'
posicao = int(url.index(find) + len(find))

BitCoin = url[ posicao : posicao + 8 ]
print("Valor BitCoin Hoje: "+ BitCoin + " R$")

url2 = request.urlopen("https://www.ativo.com/calendario/inscricoes/america-do-sul/br/mg/belo-horizonte/corrida-de-rua/36044/park-run-2019").read()
url2 = str(url2)
find = '<div class="row_header titulo_evento"'
posicao1 = int(url2.index(find) + len(find))

Running = url2[posicao1 : posicao1 + 4]
print("Corrida BH:  2019"  + Running)

Result:

/usr/bin/python3.6 /home/system/Documents/Labs/Python/CrawlerPy/Crawler.py 
Valor BitCoin Hoje: 15186,97 R$ 
Traceback (most recent call last): File "/home/system/Documents/Labs/Python/CrawlerPy/Crawler.py", line 14, in <module> posicao1 = url2.index(find) + len(find) 
ValueError: substring not found Process finished with exit code 1
    
asked by anonymous 30.12.2018 / 19:05

1 answer

0

I think code url2.index(find) is not finding anything.

  

* Knowing that find = '<div class="row_header titulo_evento"'

I made a quick visit to site and tried to find this element and did not find it.

In addition to looking at the site response you can also use the JavaScript command to try to find this element $('div.row_header.titulo_evento').length     

30.12.2018 / 20:45