Use Python to carry the pictures of the watercress sister to the Baidu net disk in bulk

Source: Internet
Author: User

first toOver hereaccording to the requirements of the Baidu PCs service to obtain a access_token, use the file upload interface needs to use.
Next, you can write the code step-by-step.

The first is the conf.py file, mainly to configure some parameters that will be used

Api_url=u ' https://pcs.baidu.com/rest/2.0/pcs/file ' method=u ' upload ' path=u '/apps/pcstest_oauth/pic2 ' Access_token =u ' 23.1c19e723c137c6f137ff1f625fa0aaa4.2592000.1414472077.328831-238347 '

Api_url is the Baidu interface address, method is required to perform the operation of the interface, path is a directory of their own network, the picture will be uploaded to this directory. Access_token is the authorization value you obtained before


#encoding: Utf-8import urllib,re,timefrom conf import api_url,method,access_token,pathimport requests# The module is used to complete uploading files num =0def GetURL (N): #解析页面所有妹子图片地址链接, returns a list containing the links url=urllib.urlopen (' http://www.dbmeizi.com/category/2?p=%d '%n) data=    Url.read () r=re.compile (R ' http://pic.dbmeizi.com/npics/[a-z0-9-]{3}/[a-z0-9-]{3}/s_p[0-9]{8}.jpg ') #用于匹配的正则表达式 Pic=r.findall (data) return picdef upload (data): #模拟一个post请求完成图片上传 files = {' file ': data2} print path+ '/mei                Zhi%d.jpg '%num params={' method ': Method, ' path ':p ath+ '/meizhi%d.jpg '%num,        ' Access_token ': Access_token,} url= '%s?%s '% (Api_url, Urllib.urlencode (params)) Print URL Response=requests.post (url,files=files) Print response.textfor page in range (1,300): Girl=geturl (page) # Prin T girl for G in Girl:url2=urllib.urlopen (g) data2=url2.read () #将图片下载到内存 upload (data2) #upload to PC      s print num num=num+1  Time.sleep (0.1) #每100ms搬运一张print ' End ' 


Use Python to carry the pictures of the watercress sister to the Baidu net disk in bulk

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.