Look I need the price of this cryptocurrency https://dex.guru/token/0x68848e1d1ffd7b38d103106c74220c1ad3494afc-bsc With this code:
import lxml
import requests
from lxml import html
html = requests.get('https://dex.guru/token/0x68848e1d1ffd7b38d103106c74220c1ad3494afc-bsc')
doc = lxml.html.fromstring(html.content)
new_releases = doc.xpath('//div[@class="0.00047061210058486165"]/text()')[0]
print(new_releases)
But I get this error
IndexError: list index out of range
I know it's raising the error because the list is empty, but why is the list empty?
Please help, I am starting with scraping.
I find a solution (imperfect one for the moment) :
You need to install 'cloudscraper' package with one js interpreter (here i used nodejs). This code sometimes failed to return data, sometimes return data. I will investigate to find out why such instability is observed.
when it works, it returns:
It's possible to build a better code with setting a session and saving temporary cookies generated by cloudflare (read 'cloudflare' doc).
Note that when their official API is released, we will prefer to use it.
Maybe cloudflare ban u if you put that kind of code in a loop without sleep() control.