Skip to content

Instantly share code, notes, and snippets.

@itherunder
Created December 16, 2021 05:26
Show Gist options
  • Save itherunder/8bda092db1aa397863485eaef2a77450 to your computer and use it in GitHub Desktop.
Save itherunder/8bda092db1aa397863485eaef2a77450 to your computer and use it in GitHub Desktop.
使用`selenium` 获取合约地址的`decimals` 以及`prices`
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
tokens = ['df574c24545e5ffecb9a659c229253d4111d87e1','c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2']
bsc_tokens = ['96dd399f9c3afda1f194182f71600f1b65946501','b59490ab09a0f526cc7305822ac65f2ab12f9723']
url = 'https://etherscan.io/token/0x%s'
bsc_url = 'https://bscscan.com/token/0x%s'
driver = webdriver.Chrome(ChromeDriverManager().install())
def get(chain):
for token in (tokens if chain == 'eth' else bsc_tokens):
driver.get((url if chain == 'eth' else bsc_url) % token)
decimal = driver.find_element_by_css_selector('#ContentPlaceHolder1_trDecimals > div > div.col-md-8')
with open('token_decimals.txt', 'a') as a:
a.write('%s#%s\n' % (token, decimal.text))
price = driver.find_element_by_css_selector('#ContentPlaceHolder1_tr_valuepertoken > div > div:nth-child(1) > span > span:nth-child(1)')
price = price.text[1:].replace(',', '')
with open('token_prices.txt', 'a') as a:
a.write('%s#%s\n' % (token, price))
# get('eth')
get('bsc')
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment