Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“我怎么能?”;点击";python中selenium的下载按钮_Python_Selenium_Selenium Chromedriver_Google Crawlers - Fatal编程技术网

“我怎么能?”;点击";python中selenium的下载按钮

“我怎么能?”;点击";python中selenium的下载按钮,python,selenium,selenium-chromedriver,google-crawlers,Python,Selenium,Selenium Chromedriver,Google Crawlers,我想使用crawler在Google analytics上下载用户数据,所以我使用selenium编写了一些代码。但是,我无法单击“导出”按钮。它总是显示错误“无此类元素”。我试图通过xpath、名称和id使用find元素。 我上传了下面的GA页面 我试过: driver.find_element_by_xpath("//*[@class='download-link']").click() driver.find_element_by_xpath('//*[@id="ID-activ

我想使用crawler在Google analytics上下载用户数据,所以我使用selenium编写了一些代码。但是,我无法单击“导出”按钮。它总是显示错误“无此类元素”。我试图通过xpath、名称和id使用find元素。 我上传了下面的GA页面

我试过:

 driver.find_element_by_xpath("//*[@class='download-link']").click()
    driver.find_element_by_xpath('//*[@id="ID-activity-userActivityTable"]/div/div[2]/span[6]/button')
    driver.find_element_by_xpath('//*[@class='_GAD.W_DECORATE_ELEMENT.C_USER_ACTIVITY_TABLE_CONTROL_ITEM_DOWNLOAD']')
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


driver = webdriver.Chrome('/Users/parkjunhong/Downloads/chromedriver')
driver.implicitly_wait(3)
usrid = '1021'
url = 'https://analytics.google.com/analytics/web/#/report/app-visitors-user-activity/a113876882w169675624p197020837/_u.date00=20190703&_u.date01=20190906&_r.userId='+usrid+'&_r.userListReportStates=%3F_u.date00=20190703%2526_u.date01=20190906%2526explorer- 
table.plotKeys=%5B%5D%2526explorer-table.rowStart=0%2526explorer- 
table.rowCount=1000&_r.userListReportId=app-visitors-user-id'
driver.get(url)
driver.find_element_by_name('identifier').send_keys('ID')
idlogin = driver.find_element_by_xpath('//*[@id="identifierNext"]/span/span')
idlogin.click()

driver.find_element_by_name('password').send_keys('PASSWD')
element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
#login
driver.find_element_by_xpath("//*[@class='download-link']").click()
#click the download button
Message: no such element: Unable to locate element
Python代码:

 driver.find_element_by_xpath("//*[@class='download-link']").click()
    driver.find_element_by_xpath('//*[@id="ID-activity-userActivityTable"]/div/div[2]/span[6]/button')
    driver.find_element_by_xpath('//*[@class='_GAD.W_DECORATE_ELEMENT.C_USER_ACTIVITY_TABLE_CONTROL_ITEM_DOWNLOAD']')
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


driver = webdriver.Chrome('/Users/parkjunhong/Downloads/chromedriver')
driver.implicitly_wait(3)
usrid = '1021'
url = 'https://analytics.google.com/analytics/web/#/report/app-visitors-user-activity/a113876882w169675624p197020837/_u.date00=20190703&_u.date01=20190906&_r.userId='+usrid+'&_r.userListReportStates=%3F_u.date00=20190703%2526_u.date01=20190906%2526explorer- 
table.plotKeys=%5B%5D%2526explorer-table.rowStart=0%2526explorer- 
table.rowCount=1000&_r.userListReportId=app-visitors-user-id'
driver.get(url)
driver.find_element_by_name('identifier').send_keys('ID')
idlogin = driver.find_element_by_xpath('//*[@id="identifierNext"]/span/span')
idlogin.click()

driver.find_element_by_name('password').send_keys('PASSWD')
element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
#login
driver.find_element_by_xpath("//*[@class='download-link']").click()
#click the download button
Message: no such element: Unable to locate element
错误:

 driver.find_element_by_xpath("//*[@class='download-link']").click()
    driver.find_element_by_xpath('//*[@id="ID-activity-userActivityTable"]/div/div[2]/span[6]/button')
    driver.find_element_by_xpath('//*[@class='_GAD.W_DECORATE_ELEMENT.C_USER_ACTIVITY_TABLE_CONTROL_ITEM_DOWNLOAD']')
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


driver = webdriver.Chrome('/Users/parkjunhong/Downloads/chromedriver')
driver.implicitly_wait(3)
usrid = '1021'
url = 'https://analytics.google.com/analytics/web/#/report/app-visitors-user-activity/a113876882w169675624p197020837/_u.date00=20190703&_u.date01=20190906&_r.userId='+usrid+'&_r.userListReportStates=%3F_u.date00=20190703%2526_u.date01=20190906%2526explorer- 
table.plotKeys=%5B%5D%2526explorer-table.rowStart=0%2526explorer- 
table.rowCount=1000&_r.userListReportId=app-visitors-user-id'
driver.get(url)
driver.find_element_by_name('identifier').send_keys('ID')
idlogin = driver.find_element_by_xpath('//*[@id="identifierNext"]/span/span')
idlogin.click()

driver.find_element_by_name('password').send_keys('PASSWD')
element = driver.find_element_by_id('passwordNext')
driver.execute_script("arguments[0].click();", element)
#login
driver.find_element_by_xpath("//*[@class='download-link']").click()
#click the download button
Message: no such element: Unable to locate element

您可以尝试使用以下文本:

如果您想单击
“导出”-

//button[contains(text(),'Export')]

您可以尝试使用以下文本:

如果您想单击
“导出”-

//button[contains(text(),'Export')]

单击元素位于iFrame中(iFrame id=“galaxyIframe”…)。因此,您需要告诉驱动程序从“主页”切换到所述iFrame。如果在
#登录后添加这一行代码,它应该可以工作:
驱动程序.切换到.frame(galaxyIframe)

(如果框架没有名称,您可以使用:
iframe=driver.find\u element\u by\u xpath(“xpath to frame”)
然后
driver.switch\u to.frame(iframe)

要返回默认帧,请使用:
driver.switch\u to.default\u content()

爬行GA通常是一种痛苦。不仅仅是因为你到处都有这些iFrame。
除此之外,我建议您研究一下爬虫块上的新成员。尽管从python切换到javascript的前景可能令人望而生畏,但这是值得的!一旦您进入它,selenium将感觉超级笨重。

您的click元素位于iFrame中(iFrame id=“galaxyIframe”…)。因此,您需要告诉驱动程序从“主页”切换到所述iFrame。如果您在
#登录后添加这行代码,它应该可以工作:
驱动程序.切换到.frame(galaxyIframe)

(如果框架没有名称,您可以使用:
iframe=driver.find\u element\u by\u xpath(“xpath to frame”)
然后
driver.switch\u to.frame(iframe)

要返回默认帧,请使用:
driver.switch\u to.default\u content()

爬行GA通常是一种痛苦。不仅仅是因为你到处都有这些iFrame。
除此之外,我建议您研究一下爬虫块上的新成员。尽管从python切换到javascript的前景可能令人望而生畏,但这是值得的!一旦您进入它,selenium会感觉超级笨重。

我已经尝试过了,但仍然显示出相同的错误…感谢您的回复,如果此解决方案不起作用,我将删除它记住,否则它很可能会被否决,你会失去声誉。是的,当然,请继续,我回复dom的时候是部分的。我已经尝试过了,但它仍然显示出相同的错误…感谢你的答复此解决方案不起作用,我会删除它,否则它很可能会被否决,你会失去声誉。是的,当然,请继续,我回复dom的时间是部分的。嗨,你能分享你的网站链接吗?或者你能给我完整的图片,这样我就可以了check@HamzaLachi我真的很感谢你的关注。我上传了更多的检查图片。嗨,你能分享你的网站链接吗?或者你能给我完整的检查图片,这样我就可以了check@HamzaLachi我真的很感谢你的关注。我上传了更多的图片。我真的很感谢你的帮助。这是工作!我真的花了很多时间在这个问题上。再次,真的感谢你的帮助!我真的很感谢你的帮助。这是工作!我真的花了很多时间在这个问题上。再次,真的感谢你的帮助!