2017-11-25 11 views
0

Google Play 뮤직 재생 목록 스크롤 기능을 자동화하려고 시도했지만 사용하지 않을 다른 솔루션은 없습니다. 스택 오버플로와 같은 일반적인 스크롤은 작동하지만 Google 뮤직 webapp는 다른 것을 사용한다고 생각합니다. 그래서 여기 내 내 코드는 지금까지자동화 Google Play 뮤직 재생 목록 스크롤 (셀렌 : 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() 

편집 :

이 그 코드를 더 스크롤 일어나고 없지만 그것이 스택 오버 플로우 웹 사이트에서 작동합니다. 해결책이있는 사람이 있습니까? 다음 (이 페이지 하단으로 스크롤 것)에

+0

무엇이 문제입니까? 무슨 일 이니? – user1767754

+0

아무 것도 일어나지 않습니다. 발생하는 스크롤링이 없습니다. – Peter

+0

'400'보다 높은 값을 넣으려고했는데 스크롤을'begin'에서'end'까지 취한 후에 두 번째 스크롤을 원하면 첫 번째 입력을 바꿀 수도 있습니다. – user1767754

답변

0

시도 :

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 

PS : 아마 페이지에 일부 제한이 : 자바 스크립트를 사용하여 body 태그의 스타일 속성을 변경할 수 있습니다 (이 스크롤 사용) :

driver.execute_script("document.body.style.overflow = 'auto';") 

스크롤을 사용하지 않으려면 "자동"대신 "숨겨진"값을 설정하십시오.

+0

스타일 속성을 어떻게 변경합니까? – Peter

+0

@Peter, 답변을 업데이트했습니다. –

+0

@ 피터, 어때? –