Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.5k views
in Technique[技术] by (71.8m points)

tkinter - My selenium web scrapper doesn't make sense to me

I want to get the bitcoin price using the following code. I have no clue why the output behaves that way. It appears to store certain values and outputs them in-between accurate values. Bonus task: Make the old values disappear in tkinter Screenshot from Output

from bs4 import BeautifulSoup #Downloading pertinent Python packages
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import tkinter as tk
import time

time = 1000



def bitcoinTracker():
    options = Options()
    options.headless = True
    options.add_argument("--window-size=1920,1200")
    chromedriver = "/Users/Philipp/PhytonWebScrap/selenium_project/chromedriver" #Setting up Chrome driver
    driver = webdriver.Chrome(options=options, executable_path=chromedriver)
    driver.get("https://coinmarketcap.com/currencies/bitcoin/")
    hunt = driver.find_element_by_class_name("priceValue___11gHJ").text
    return(hunt)
    driver.quit()
    
def collector():
    label = tk.Label(text="Bitcoin " + bitcoinTracker(), font="Arial 18")
    label.pack()
    root.after(time, collector)
    
root = tk.Tk()
root.after(time, collector)
root.mainloop()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I try again this time only selenium without tkinter

from bs4 import BeautifulSoup #Downloading pertinent Python packages
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

options = Options()
options.headless = True
options.add_argument("--window-size=1920,1200")

while True:
    chromedriver = "/Users/Philipp/PhytonWebScrap/selenium_project/chromedriver" #Setting up Chrome driver
    driver = webdriver.Chrome(options=options, executable_path=chromedriver)
    driver.get("https://coinmarketcap.com/currencies/bitcoin/")
    hunt = driver.find_element_by_class_name("priceValue___11gHJ").text
    #print(driver.page_source)
    time.sleep(20)
    print(hunt)
driver.quit()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...