我需要下载网页上有下载按钮的所有文件,例如此页面:http://a.vmall.com/topic/list/d6aac030f17e49d990b8a1996e872d53,每个应用都有一个下载按钮,要求您点击"下载"在网站上,然后开始下载
如何编写python或selenium脚本以自动下载具有" download"的所有文件。按钮?感谢
答案 0 :(得分:2)
selenium 在这里没用,只需使用BeautifulSoup来获取链接即可。
例如:
import re
import requests
from bs4 import BeautifulSoup
link = 'http://a.vmall.com/topic/list/d6aac030f17e49d990b8a1996e872d53'
r = requests.get(link)
soup = BeautifulSoup(r.text, "html.parser")
for i in soup.find_all('a', {'class': "app-btn-down"}):
print(re.search('http://.*\.apk', i.get('href')).group(0))
输出:
http://122.11.38.214/dl/appdl/application/apk/72/723e6026cf0f4a2eb4b7f564f6c82715/com.google.android.wearable.app.cn.1510301352.apk
http://122.11.38.214/dl/appdl/application/apk/17/1768953363fc4bc39957bc2d1a8e0cb0/com.flightmanager.view.1510161532.apk
http://122.11.38.214/dl/appdl/application/apk/49/494ce5d2b4074fc8a47709fc10145d80/com.tencent.qqlite.1510191652.apk
http://122.11.38.214/dl/appdl/application/apk/6d/6de0e6ea05ee4b53a6a730912f1cb732/com.tencent.news.1510271932.apk
http://122.11.38.214/dl/appdl/application/apk/82/82ff5be0aee442feb6501f604e30c815/com.eg.android.AlipayGphone.1510291547.apk
http://122.11.38.214/dl/appdl/application/apk/5a/5ae799a7fb4545e4903abaf2b5800751/ctrip.android.view.1511051017.apk
http://122.11.38.214/dl/appdl/application/apk/64/643e6561255a473aaa3348b36d045404/com.tencent.mm.1510201247.apk
然后你可以保存链接,或使用其他包如urllib或请求下载它们。
答案 1 :(得分:0)
我认为你应该以艰难的方式尝试:
btns = driver.find_elements_by_tag_name("a")
for btn in btns:
btn.click()