'Trying to get value determined by javascript using selenium
As title says, I am currently trying to acquire a dynamic value. I am lost as originally I was using beautiful soup and found out the value was dynamic. Here are how the values are determined
.call({from: from})
.then(function(res) {
console.log("Node Price (Wei AVAX): " + res);
const avax = Number(Web3.utils.fromWei(res, 'ether'));
console.log("Node Price (AVAX): " + avax);
const items = document.querySelectorAll(".node-info-price-avax");
items.forEach(i => {
i.innerHTML = avax.toFixed(2) + " AVAX";
});
})
Then here is how its displayed,
<span class="node-info-price-avax">27.88 AVAX</span>
I've been watching tutorials and reading over guides all day and can not for the love of me figure out how to acquire said value.
Solution 1:[1]
I found a pretty detailed video that did exactly what I was looking for.
The solution was finding the data I needed and copying the xpath by using find_element, then I appened it to a list and used pandas to make it look pretty. Here is the finished code:
from selenium import webdriver
import pandas as pd
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://playa3ull.games")
node_data = driver.find_elements_by_class_name('wpb_wrapper')
data_list = []
for data in node_data:
node_price = data.find_element_by_xpath('//*[@id="pb-node-info-table"]/tbody/tr[6]/td[2]/span[1]').text
nodes_sold = data.find_element_by_xpath('//*[@id="pb-node-info-table"]/tbody/tr[3]/td[2]').text
token_price = data.find_element_by_xpath('//*[@id="pb-node-info-table"]/tbody/tr[6]/td[2]/span[2]').text
data_item = {
'Node Price': node_price,
'Nodes Sold': nodes_sold,
'Token Price': token_price
}
data_list.append(data_item)
df = pd.DataFrame(data_list)
df_last = df[-1]
print(df_last)
Here is the link for a more detailed explanation: youtube.com/watch?v=lTypMlVBFM4
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tomerikoo |
