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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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返回unknownProtocolFound错误_Python_Selenium_Iframe - Fatal编程技术网

Python Selenium返回unknownProtocolFound错误

Python Selenium返回unknownProtocolFound错误,python,selenium,iframe,Python,Selenium,Iframe,我正在尝试使用Firefox Webdriver、Selenium和Python从[this GooglePlay direct link generator][1]下载一个APK文件 问题是,当Selenium尝试获取主页时,它会崩溃,并显示以下错误消息: /usr/bin/python2.7 /home/ghasemi/PycharmProjects/phorcys_watcher/main.py http://apps.evozi.com/apk-downloader/?id=com.in

我正在尝试使用Firefox Webdriver、Selenium和Python从[this GooglePlay direct link generator][1]下载一个APK文件

问题是,当Selenium尝试获取主页时,它会崩溃,并显示以下错误消息:

/usr/bin/python2.7 /home/ghasemi/PycharmProjects/phorcys_watcher/main.py
http://apps.evozi.com/apk-downloader/?id=com.instagram.android
Traceback (most recent call last):
  File "/home/ghasemi/PycharmProjects/phorcys_watcher/main.py", line 7, in <module>
    content = google_play_download("com.instagram.android")
  File "/home/ghasemi/PycharmProjects/phorcys_watcher/collector.py", line 20, in google_play_download
    browser.get("https://apps.evozi.com/apk-downloader/?id=" + app_page_id)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 268, in get
    self.execute(Command.GET, {'url': url})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=unknownProtocolFound&u=httpss%3A//www.adnetworkperformance.com/script/java.php%3Foption%3Drotateur%26r%3D411313%26treqn%3D1025813717%26runauction%3D1%26crr%3D168ce9d76b1a6695b12e%2CwcwHrNzGnshFns2PnM3bbcwGW8xLz-mNycwuvZjurZja3MzJfMxG_9xMX4wYns7a2YxHvshBL9xe3shbjN2J7umN6umNm-mNuN2czNw723956800778f24b2db6%26rtid%3D595b6ecb8ac19%26cbrandom%3D0.7519066097934798%26cbtitle%3DAPK%2520Downloader%2520%255BLatest%255D%2520Download%2520Directly%2520%257C%2520Chrome%2520Extension%2520v3%2520%28Evozi%2520Official%29%26cbiframe%3D0%26cbWidth%3D1280%26cbHeight%3D717%26cbdescription%3DDownload%2520APKs%2520Directly%2520From%2520Google%2520Play%2520To%2520Your%2520Computer%2520With%2520APK%2520Downloader%2520Extension%2520For%2520Google%2520Chrome%26cbkeywords%3D%26cbref%3D&c=&f=regular&d=Firefox%20doesn%E2%80%99t%20know%20how%20to%20open%20this%20address%2C%20because%20one%20of%20the%20following%20protocols%20%28httpss%29%20isn%E2%80%99t%20associated%20with%20any%20program%20or%20is%20not%20allowed%20in%20this%20context.

一种解决方案是url解析函数,在driver.get(url)之前调用每个url

然后你会像这样使用它

url = url_parser(url)
driver.get(url)

你就快到了

import requests
import time
from selenium import webdriver

def google_play_download(app_page_id):
    browser = webdriver.Chrome()
    browser.get("https://apps.evozi.com/apk-downloader/?id=" + app_page_id)
    browser.find_element_by_css_selector(".btn.btn-primary.btn-lg.btn-block").click()
    time.sleep(10)

    apk_link = browser.find_element_by_css_selector(".btn.btn-success.btn-block").get_attribute('href')
    browser.quit()
    for rnd in range(5):
        resp = requests.get(apk_link)
        if resp.headers['Content-Length'] == str(len(resp.content)):
            return resp.content


if __name__ == "__main__":
    content = google_play_download("com.instagram.android")
    f = open('file.apk', 'wb')
    f.write(content)
    f.close()

解析器无法在此行
apk\u link=browser中提取正确的url。请通过\u css\u选择器(“.btn.btn success.btn block”)查找\u元素。\u获取属性('href')

当您打印url时,它会显示
https://apps.evozi.com/apk-downloader/?id=com.instagram.android

把电话换成

apk_link = browser.find_element_by_css_selector(".btn.btn-success.btn-block")
ele=apk_link.get_attribute('href')

for rnd in range(5):
      resp = requests.get(ele)
      if resp.headers['Content-Length'] == str(len(resp.content)):
            return resp.content

代码将正常工作

驱动程序本身试图获取错误的URL,而不是我。我使用驱动程序获得正确的URL。在这个正确的URL的响应中,有一些链接(例如图像)和“iframe”,驱动程序试图下载它们并发出隆隆声!你能粘贴你的代码吗。然后我可以告诉您在哪里使用url解析器函数。您必须有某种链接中的for-link循环,它将url发送到webdriver…您有一个变量-url-连续五次向请求提供。url的内容应该来自哪里?你理解这个问题吗?问题在于页面的iFrame中存在错误的协议。超时对问题没有任何作用。谢谢。如果你运行这段代码,它会下载你想要的apk。。。您只需要正确的css选择器来获取id(表示成功的那个),然后您还需要睡眠。该网站本身表示,准备apk链接可能需要3分钟,因此在下载url存在之前查找该url不会返回任何下载url。顺便说一下,你应该考虑改变这个问题的话题,因为它从来就不是一个问题。我无法重现您最初发布的错误。试图将不存在的变量url传递给请求时,代码崩溃。
url = url_parser(url)
driver.get(url)
import requests
import time
from selenium import webdriver

def google_play_download(app_page_id):
    browser = webdriver.Chrome()
    browser.get("https://apps.evozi.com/apk-downloader/?id=" + app_page_id)
    browser.find_element_by_css_selector(".btn.btn-primary.btn-lg.btn-block").click()
    time.sleep(10)

    apk_link = browser.find_element_by_css_selector(".btn.btn-success.btn-block").get_attribute('href')
    browser.quit()
    for rnd in range(5):
        resp = requests.get(apk_link)
        if resp.headers['Content-Length'] == str(len(resp.content)):
            return resp.content


if __name__ == "__main__":
    content = google_play_download("com.instagram.android")
    f = open('file.apk', 'wb')
    f.write(content)
    f.close()
apk_link = browser.find_element_by_css_selector(".btn.btn-success.btn-block")
ele=apk_link.get_attribute('href')

for rnd in range(5):
      resp = requests.get(ele)
      if resp.headers['Content-Length'] == str(len(resp.content)):
            return resp.content