selenium爬取必应高清壁纸
```pythonimport os
import re
import time
from selenium import webdriver
id=1
path = './必应壁纸'
if not os.path.exists(path):
os.makedirs(path)
profile = {'download.default_directory': r'E:\Django\taobao\必应壁纸',#设置下载路径
'profile.default_content_setting_values': {
'images': 1,#设置浏览器无图模式 1,有图;2无图
}
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('headless') # 设置隐藏浏览器
chrome_options.add_experimental_option('prefs', profile)
driver = webdriver.Chrome(options=chrome_options)
driver.implicitly_wait(10)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
for i in range(1,133):
driver.get('https://bing.ioliu.cn/?p=%s'%(i))
download = driver.find_elements_by_xpath("//div[@class='options']/a")
for a in download:
a.click()
srt = a.get_attribute('href')
arr = re.split("[/|?]", srt)
while True:
time.sleep(3)
if os.path.exists(path + "/" +arr[-2] + '_1920x1080.jpg'):
print(str(id)+": "+arr[-2] + '_1920x1080.jpg:'+'文件下载完成')
id+=1
break
driver.quit()
```
那个大神能告诉我.selenium 怎么获取下载文件名.非常感谢 本帖最后由 SN1t2lO 于 2020-7-10 14:07 编辑
燃鹅,bing壁纸是官方接口的;www,这是我自用的采集软件配置文件,另外bing壁纸一般是1920*1200的哦。
链接: https://pan.baidu.com/s/1ye4M5BgOHb6zO26Vzi1vEA 提取码: hhus
{
"AutoSet": false,
"BaseUrl": "http://global.bing.com/",
"BingUrls": [
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=en-us"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=zh-cn"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=ja-jp"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=en-ww"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=en-gb"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=en-au"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=en-ca"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=fr-fr"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=de-de"
},
{
"Url": "http://global.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&setmkt=pt-br"
}
],
"Collect": true,
"CollectFolder": "MYPICTURES\\Bing\\old",
"Definition": true,
"Folder": "MYPICTURES\\Bing",
"Images": 8,
"LimitCount": true,
"Quiet": true
} 感谢分享,学习了 SN1t2lO 发表于 2020-7-10 14:04
燃鹅,bing壁纸是官方接口的,这是我自用的采集软件配置文件,另外bing壁纸一般是1920*1200的哦。
链 ...
我是用chrome打开网页.点击下载按钮,下载的.
页:
[1]