因此,我試圖自動滾動我的谷歌播放音樂播放列表,但它沒有拿起,我什麼都沒有使用其他解決方案。正常滾動就像堆棧溢出一樣,但我認爲Google Music webapp使用了不同的東西。所以這是我到目前爲止我的代碼自動化谷歌播放音樂播放列表滾動與Python中的硒
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from bs4 import BeautifulSoup
from selenium.webdriver.common.action_chains import ActionChains
profile = webdriver.FirefoxProfile(r"C:\Users\Richard\AppData\Roaming\Mozilla\Firefox\Profiles\puom7wwz.default-1468625172145")
driver = webdriver.Firefox(executable_path=r'geckodriver.exe',firefox_profile=profile)
driver.get("https://play.google.com/music/listen?u=1#/pl/AMaBXymw0YGY7Y-z1B-FdrwkDCm7WdO_kyK4x4xQqn_vZsg56-VzwjsRKaQPypMs88oIKHn4qZd5aDbFbh5ojt6DpoZZCyHgCA%3D%3D")
driver.find_element_by_id("gb_70").click()
time.sleep(2)
element = driver.find_element_by_xpath("//*[contains(text(), 'William Thomas')]").click()
time.sleep(2)
password_field = driver.find_element_by_name("password")
password_field.clear()
password_field.send_keys("IcewindDale1995%")
password_field.send_keys(u'\ue007') #unicode for enter key
time.sleep(10)
driver.get("https://stackoverflow.com/questions/44370208/clicking-on-link-through-google-with-selenium-web-driver")
#driver.find_element_by_id("gba_70").click()
source = driver.page_source
soup = BeautifulSoup(source, "html.parser")
time.sleep(10)
#driver.execute_script("document.getElementById('descriptionWrapper').focus();")
#time.sleep(10)
driver.execute_script("window.scrollTo(0, 400)")
# i = 0
# while i<1000:
# scroll = driver.find_element_by_id('descriptionWrapper').send_keys(Keys.PAGE_DOWN)
# i+=1
driver.find_element_by_id("gba_70").click()
with open('page1.html', 'w', encoding="utf-8") as fid:
fid.write(str(soup))
driver.close()
編輯:
沒有滾動條的情況下發生的代碼,但它的作品堆棧溢出網站上。 任何人都有解決方案嗎?
問題是什麼?發生什麼事? – user1767754
什麼都沒有發生。沒有正在發生的滾動。 – Peter
如果您嘗試放置高於「400」的值,並且滾動到「開始」到「結束」,您可能會更改第一個輸入以及如果要再次滾動。 – user1767754