Python implementation crawl 30 pages of Baidu Campus goddess pictures!

Source: Internet
Author: User

1, the following is the source code

Import requests

Import OS

def getmanypages (keyword,pages):

Params=[]

For I in Range (30,30*pages+30,30):

#以下是请求服务器参数, you can find it in the browser

Params.append ({

' TN ': ' resultjson_com ',

' IPN ': ' RJ ',

' CT ': 201326592,

' Is ': ',

' FP ': ' Result ',

' Queryword ': keyword,

' CL ': 2,

' LM ':-1,

' IE ': ' utf-8 ',

' OE ': ' utf-8 ',

' Adpicid ': ',

' St ':-1,

' Z ': ',

' IC ': 0,

' word ': keyword,

' s ': ',

' SE ': ',

' tab ': ',

' Width ': ',

' Height ': ',

' Face ': 0,

' Istype ': 2,

' QC ': ',

' NC ': 1,

' FR ': ',

' PN ': I,

' RN ': 30,

' GSM ': ' 1e ',

' 1517540092108 ': '

})

url = ' Https://image.baidu.com/search/acjson '

URLs = []

For I in params:

Urls.append (Requests.get (url,params=i). JSON (). Get (' data '))

return URLs



def getimg (DataList, LocalPath):


If not os.path.exists (LocalPath): # New Folder

Os.mkdir (LocalPath)

x = 300

For list in dataList:

For I in list:

If I.get (' Middleurl ')! = None:

Print (' Downloading:%s '% i.get (' Middleurl '))

IR = requests.get (i.get (' Middleurl '))

Open (LocalPath + '%d.jpg '% x, ' WB '). Write (Ir.content)

x + = 1

Else

Print (' Picture link does not exist ')


if __name__ = = ' __main__ ':

DataList = getmanypages (' Campus goddess ', 10) # parameter 1: The type of picture you want to find (I'm looking for a campus goddess), Parameter 2: number of pages to download

Getimg (dataList, ' f:/pics/') # parameter 2: Save the path I saved here under the F-Disk Pics folder


2.

3, after the implementation of the results such as





Python Implementation Crawl 30 page Baidu Campus Goddess Pictures!

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.