将带有Python和Selenium的APK上载到解释为URL的网页
我想使用selenium和Python将一个.apk文件上传到卡巴斯基的在线扫描仪。但是,当我使用selenium的send_keys()方法时,该文件被解释为URL 相关的HTML如下所示:将带有Python和Selenium的APK上载到解释为URL的网页,python,selenium,file-upload,apk,antivirus,Python,Selenium,File Upload,Apk,Antivirus,我想使用selenium和Python将一个.apk文件上传到卡巴斯基的在线扫描仪。但是,当我使用selenium的send_keys()方法时,该文件被解释为URL 相关的HTML如下所示: <div class="container"> <div class="div-field-home"> <div class="div-hero-scanner-wrapper"> <!-- ======= -->
<div class="container">
<div class="div-field-home">
<div class="div-hero-scanner-wrapper">
<!-- ======= -->
<div class="acenter pdv-1x" id="drop-area">
<form action="" id="SendForm">
<div class="d-inline">
<div class="tags-inline amiddle file-load-group">
<input id="txt-input-01" type="text" class="small" placeholder="Drag-and-drop a file or paste a link here" maxlength="2000" txtvalue="">
<a href="#" class="d-inline bt-attach bt-attach-file"><img src="/resources/img/attach.png" class="w-100" alt=""><img src="/resources/img/attach_inactive.png" class="w-100" alt=""></a>
<a href="#" class="btn upper small bt-attach-res bt-attach-file">Attach file</a>
<a href="#" class="btn upper clr-ff bg-02 small bt-check bt-disable" analytics-event="StartScan.Click">Scan</a>
</div>
我还尝试将输入type=text
更改为type=file
。它已更改,但相同的错误仍在发生。
我认为问题可能在于,必须单击文件攻击链接才能将文本解释为文件。但不完全确定
任何帮助都将不胜感激 看来你离得够近了。要将
.apk
文件上载到using,您需要引导WebDriverWait使元素可单击()
,同时:
- 从本地系统拖放
文件,或apk
- 提供
url的链接apk
按照提供
apk
url链接的第二种方法,您可以使用以下任一方法:
- 使用
:CSS\u选择器
driver.get('https://virusdesk.kaspersky.com/#') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txt-input-01"))).send_keys("https://drive.google.com/file/d/1ZspxTOnQpqcuvI0rDAkBsB_Y-gRzIEaq/view/GranthamBuild14022020.apk")
- 使用
:XPATH
driver.get('https://virusdesk.kaspersky.com/#') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txt-input-01']"))).send_keys("https://drive.google.com/file/d/1ZspxTOnQpqcuvI0rDAkBsB_Y-gRzIEaq/view/GranthamBuild14022020.apk")
- 注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
- 浏览器快照:
谢谢你的回答。但是,此解决方案只扫描URL,而不扫描文件本身。因此,如果我给它一个恶意apk的url,它会说url是好的-如果我(手动)上传文件,它会说它包含威胁。@这是一个基于的解决方案,它可以帮助你用有效的字符序列填充
标记,而不考虑网站执行的验证,这超出了这个问题的范围。
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC