首页
时事
归档
壁纸
更多
留言
关于
邻里
Search
1
使用必应Bing每日图片做网站背景(自动)
2,987 阅读
2
vue的输入值校验规则整理
1,662 阅读
3
VUE `ERR_CONNECTION_TIMED_OUT`的解决办法
1,628 阅读
4
好站推荐-https://wangchujiang.com/linux-command/
1,598 阅读
5
微信支付开发前准备(小程序、公众号、App、H5)
1,582 阅读
文章
图说
代码
吐槽
登录
Search
标签搜索
Linux
laravel
windows
TYPO3
php
shell脚本
git
微信
好站
vue
第三方登录
centos
linxu
centos7
thinkPHP
微信支付
api
MySQL
桌面
必应首图
Beer
累计撰写
114
篇文章
累计收到
22
条评论
首页
栏目
文章
图说
代码
吐槽
页面
时事
归档
壁纸
留言
关于
邻里
搜索到
2
篇与
必应首图
的结果
2019-02-27
爬取必应首页大图 - Python
不废话,直接上代码# -*- coding: utf-8 -*- # @Author: Wang Hongbin # @Email: wanghongbin@ngoos.org # @Date: 2018-03-16 14:19:27 # @Last Modified by: Wang Hongbin # @Last Modified time: 2018-03-28 16:26:07 import requests import re import os import time #时间模块 local = time.strftime("%Y-%m-%d_") baseUrl = "https://cn.bing.com" headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36'} def getImgUrl(url): reg1 = r"(/az/hprichbg/rb/.*?.jpg)" con = requests.get(url) content = con.text imgUrl = re.findall(reg1, content, re.S)[0] # imgLink = baseUrl+imgUrl return imgUrl def getFilePath(): # filePath = '/var/www/html/biYinPic/images/' + time.strftime("%Y%m%d") + '/' filePath = 'C:/Users/Administrator/Pictures/MyDesktop/' if not os.path.exists(filePath): os.mkdir(filePath) return filePath def getImgName(url): reg2 = r"/az/hprichbg/rb/(.*?)_" imgName = re.findall(reg2, url, re.S)[0] imgName = local + imgName + '.jpg' return imgName def downloadByPic(url): imgUrl = getImgUrl(url) imgName = getImgName(imgUrl) filePath = getFilePath() fileName = filePath+imgName picUrl = baseUrl + imgUrl read = requests.get(picUrl) f = open(fileName, 'wb') f.write(read.content) f.close() # reg3 = r'<div class=\"hplaCata\"><div class=\"hplatt\">(.*)</div><div class=\"hplats\">(.*)</div><div id=\"hplaSnippet\">(.*)</div><div class=\"hplaPvd\">(.*)</div>' downloadByPic(baseUrl) print('is ok!')爬取结果下图是七月份至今的爬取图片,因为是在window上执行的,电脑不开机的时候不会执行,代码放在Linux上执行也没问题,使用crontab启个定时器就行了
2019年02月27日
661 阅读
0 评论
0 点赞
2019-02-27
爬取必应首页大图 - PHP
不废话,直接上代码<?php /** * 获取bing首页大图保存在本地 * @Author: Wang Hongbin * @Email: wanghongbin@ngoos.org * @Date: 2018-02-24 15:21:40 * @Last Modified by: Wang Hongbin * @Last Modified time: 2018-02-24 15:36:52 */ class GetBingPic { private $bingApiXml; private $bingApiJson; function __construct() { // 返回xml格式 $this->bingApiXml = "http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1"; // 返回json格式 $this->bingApiJson = "http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"; } /** * xml格式数据 * @return [type] [description] */ public function getDataXml() { $url = $this->bingApiXml; $data = $this->httpGet($url); return $data; } /** * json格式数据 * @return [type] [description] */ public function getDataXml() { $url = $this->bingApiJson; $data = $this->httpGet($url); return $data; } private function httpGet($url) { $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 500); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_URL, $url); $res = curl_exec($curl); curl_close($curl); return $res; } } $BingPic = new GetBingPic(); $xmldata = $BingPic->getDataXml(); var_dump($xmldata);爬取结果下图是七月份至今的爬取图片,因为是在window上执行的,电脑不开机的时候不会执行,代码放在Linux上执行也没问题,使用crontab启个定时器就行了啰嗦几句其实也没啥,就是还有python的版本 爬取必应首页大图 - Python
2019年02月27日
602 阅读
0 评论
0 点赞