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!