Making a script to get updates when your voting power is 100% Part 02

avatar

Hello everyone!

I hope you are all doing well!

Here are some new updates I would like to share with you about the web scraper.

Update 1
Based off of my TA @bhanutejap I migrated to using selenium with python

This is what he posted

python
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Users\bteja\Documents\geckodriver.exe') ##this is the path where my geckodriver exists
hivestats_url = 'https://hivestats.io/@bhanutejap'
driver.get(hivestats_url)
vote_value_percentage = driver.find_elements_by_xpath('/html/body/div/div/div[1]/div/div[2]/section[1]/div[2]/div/div/span[1]/span[2]')
print(vote_value_percentage[0].text)

When I first tested this, it worked wonderfully and showed that I had 100% voting power!

I got excited!

But once I voted and ran the code again it gave me the error below

print(vote_value_percentage[0].text)
IndexError: list index out of range

I modified the code a little but the issue remains the same

My code:

python
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options as FirefoxOptions

options = FirefoxOptions()
options.add_argument("--headless")



driver = webdriver.Firefox(options=options) #this is the path where my geckodriver exists

def get_voting_power(username):

    hivestats_url = 'https://hivestats.io/@' + username
    driver.get(hivestats_url)
    vote_value_percentage = driver.find_elements_by_xpath('/html/body/div/div/div[1]/div/div[2]/section[1]/div[2]/div/div/span[1]/span[2]')
   #/html/body/div/div/div[1]/div/div[2]/section[1]/div[2]/div/div/span[1]/span[2]
    
    return vote_value_percentage[0].text

username = "armoredbanana"
response = get_voting_power(username)

print("The user: ", username, " has: ", response, " voting power")

But if we use

python
print(vote_value_percentage)

It outputs an empty list as the answer.

This means that our code is not picking up the xpath, but when it is 100% it does!

python output
100.00%

It gets even more interesting

I reran @bhanutejap 's code and found to give me 100% as well
Furthermore to investigate I grabbed the xpath of the time that it will take for my voting power to re charge, which is 2 hours right now. But look at what I get as the output

output
Never voted before.

Very strange. The web scraper is getting data that I have never voted before, or that I have 100% voting power.

Conclusion

I am not sure what is going on, but whatever it is, its very interesting! I will keep you guys updated on how it goes and if you have any suggestions please feel free to let me know!

Thanks!



0
0
0.000
2 comments
avatar
(Edited)

@armoredbanana I see the issue, if we observe the page while loading, initially it's 100% but after a certain delay, the actual value is showing up. This can be seen if you observe the firefox page while loading when it's opened from the script.
We can resolve this in two ways, first is to use time.sleep(3) before getting the element using driver.find_elements_by_xpath, the other option is to use Selenium-python waits.
I'll follow your steps and keep you posted with my results.
Meanwhile, you may want to check these out:
https://selenium-python.readthedocs.io/waits.html
https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python

0
0
0.000
avatar

Congratulations @armoredbanana! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

You received more than 100 upvotes.
Your next target is to reach 200 upvotes.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Check out the last post from @hivebuzz:

Hive Power Up Day - March 1st 2022
Hive Power Up Month - Feedback from February day 28
Support the HiveBuzz project. Vote for our proposal!
0
0
0.000