Created
October 27, 2021 19:18
-
-
Save bboynton97/6120d66f469495df6681724afb7ae97c to your computer and use it in GitHub Desktop.
Auto-list NFTs on OpenSea with Browser Automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First install Chrome, and the Selenium driver | |
# Next, download and save the MetaMask CRX (there are plenty of guides on how to do this) | |
from selenium import webdriver | |
from webdriver_manager.chrome import ChromeDriverManager | |
from selenium.webdriver.chrome.options import Options | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.common.keys import Keys | |
import time | |
# The first time you do this, you'll need to connect your metamask wallet | |
# Leave the browser open with only one tab | |
op = Options() | |
op.add_extension('metamask.crx') # <-- route to the CRX file | |
chrome = webdriver.Chrome(ChromeDriverManager().install(), options=op) | |
chain = 'matic' # Change for other chains, but if you're using other chains just use the API instead | |
collection_address = '0x000' # Pull this from the URL of your collection | |
price = '0.0069' # must be a string | |
def list(i): | |
# Main window | |
chrome.switch_to.window(chrome.window_handles[0]) | |
# Go to sale page | |
chrome.get('https://opensea.io/assets/{}/{}/{}/sell'.format(chain, collection_address, i)) | |
# Check that it isn't already for sale - nevermind it just lists it again | |
# Set price | |
for i in range(50): # See if it's there | |
try: | |
chrome.find_element(By.XPATH, '//input[@name="price"]') | |
break | |
except: | |
time.sleep(0.5) | |
chrome.find_element(By.XPATH, '//input[@name="price"]').send_keys(price + Keys.RETURN) | |
# Click sign | |
for i in range(50): | |
try: | |
chrome.find_element(By.XPATH, '//button[text()="Sign"]') | |
break | |
except: | |
time.sleep(0.5) | |
chrome.find_element(By.XPATH, '//button[text()="Sign"]').click() | |
# Switch to new window | |
time.sleep(1) | |
chrome.switch_to.window(chrome.window_handles[1]) | |
# Click sign | |
for i in range(50): | |
try: | |
chrome.find_element(By.XPATH, '//button[text()="Sign"]') | |
break | |
except: | |
time.sleep(0.5) | |
chrome.find_element(By.XPATH, '//button[text()="Sign"]').click() | |
start = int(input("Start index (included): ")) | |
end = int(input("End index (included): ")) | |
for i in range(start, end+1): | |
list(i) | |
print("Ended listing") |
@tommytoolman On line 14, you'll have to enter the relative route to your metamask.crx
file. The current code as written will only work if the crx
file is in the same directory as list.py
This is awesome! Does it still work? And have you tried running this from a cloud service?
hi, you help so much, but how to automatically set the date?
This is awesome! Does it still work? And have you tried running this from a cloud service?
Hi brother I am having error could you help it stuck adding on connectin metamask and then nothing does
How to change Duration. Default - 7 Days.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi this looks fantastic. I tried using myself but I am getting a runtime error that the metamask extension cannot be found. Running from VS - where are you executing the list.py file from? May thanks, Tom