userHG
userHG

Reputation: 589

Scraping Google Play Store BeautifulSoup / Selenium

I'm scraping data from the Android Store (Google Play Store) and I want to automate the downloading process on a connected phone. I'm trying to automate the click on the 'Install' button in an app page with Selenium but I can't click on it

Here is my python code :

from selenium import webdriver
driver=webdriver.Safari()
driver.get("https://play.google.com/store/apps/details? 
             id=com.playdemic.golf.android")


dr_button = driver.find_element_by_xpath("//*[@id='fcxH9b']/div[4]/c-wiz/div/div[2]/div/div[1]/div/c-wiz[1]/c-wiz[1]/div/div[2]/div/div[2]/div/div[2]/div[2]/c-wiz/div/span/button")
dr_button.click()

Upvotes: 2

Views: 2586

Answers (3)

userHG
userHG

Reputation: 589

EDIT

I solved 90% of the problem with Safari, I had first to log in here is my code.

driver = webdriver.Safari()
driver.get("https://play.google.com/store/apps/details? 
id=com.king.candycrushsaga")

connexionbutton= "//*[@id='gb_70']"
emailfield= "identifierId"
GoogleAccUser="*****@gmail.com"
GoogleAccPassword="*****"
passwordfield="//*[@id='password']/div[1]/div/div[1]/input"
nextButton = "//*[@id='identifierNext']/content/span"
nextButtonTwo = "//*[@id='passwordNext']/content/span"
appsTabW  = "//*[@id='wrapper']/div[1]/div/ul/li[2]/a/span/span[2]"
appsTab = "//*[@id='wrapper']/div[1]/div/ul/li[2]/a"
installButton = "//*[@id='fcxH9b']/div[4]/c- 
wiz/div/div[2]/div/div[1]/div/c-wiz[1]/c- 
wiz[1]/div/div[2]/div/div[2]/div/div[2]/div[2]/c-wiz/div/span/button"
confirmInstallButton = "//*[@id='purchase-ok-button']/span"
xx = "//*[@id='purchase-cancel-button']"



loginbuttonElement = WebDriverWait(driver,10).until(lambda driver: 
driver.find_element_by_xpath(xpathbutton))
loginbuttonElement.click()

emailFieldElement = WebDriverWait(driver,10).until(lambda driver: 
driver.find_element_by_id(emailfield))
emailFieldElement.clear()
emailFieldElement.send_keys(GoogleAccUser)

nextButtonElement = WebDriverWait(driver,10).until(lambda driver: 
driver.find_element_by_xpath(nextButton))
nextButtonElement.click()

passwordFieldElement = WebDriverWait(driver,10).until(lambda driver: 
driver.find_element_by_xpath(passwordfield))
passwordFieldElement.clear()
passwordFieldElement.send_keys(GoogleAccPassword)

nextButtonElementTwo = WebDriverWait(driver,10).until(lambda driver: 
driver.find_element_by_xpath(nextButtonTwo))
nextButtonElementTwo.click()

 installButtonElement = WebDriverWait(driver,10).until(lambda driver: 
 driver.find_element_by_xpath(installButton))
 installButtonElement.click()

confirmInstallButtonElement = WebDriverWait(driver,50).until(lambda 
 driver: driver.find_element_by_xpath(xx))
 confirmInstallButtonElement.click()

Now the problem is the Install confirmation which is on a popup window and I can't detect the button to click on it and download the app

Upvotes: 1

crookedleaf
crookedleaf

Reputation: 2198

The problem is Google uses element obfuscation to prevent automation against their site in a malicious manner. You are on the right path with using XPATH, but you're going to have to manually create the XPATH... path.. which will help simplify your code, anyway. You could so something such as:

dr_button = driver.find_element_by_xpath("//button[@aria-label='Install']")

EDIT: To clarify on element obfuscation, you can see all the class names, as well as other element attributes are a seemingly random 6 character alpha numeric string. These strings can and will change intermittently. Most element-finding is used my element id's and classes.

Upvotes: 1

Lukas
Lukas

Reputation: 446

I have to log in, but i can click on "install"! :) Try other browser? RESULT FOR:

from selenium import webdriver
driver=webdriver.Firefox()
driver.get("https://play.google.com/store/apps/details?id=com.playdemic.golf.android")


dr_button = driver.find_element_by_xpath("//*[@id='fcxH9b']/div[4]/c-wiz/div/div[2]/div/div[1]/div/c-wiz[1]/c-wiz[1]/div/div[2]/div/div[2]/div/div[2]/div[2]/c-wiz/div/span/button")
dr_button.click()

Upvotes: 0

Related Questions