Crawler, how should the notes be written?
Standard Style
This is a standard style, r=requests.request (Get,params, and other parameters), parameters are headers, is user_agent, is the user agent, the default this is Python requests, but some sites do not support, Like Amazon. So we have to add User agent parameters, (can be replaced by the Google browser to open user interface, there is.) Also downloaded a plugin user_agent switcher, want to change what kind of can.
1 ImportRequests2 ImportOS3Root ='d://pics//'4Url='http://www.nationalgeographic.com.cn/photography/photo_of_the_day/4309.html'5Path = root + Url.split ('/') [-1]6 Try:7 if notos.path.exists (Root):8 Os.mkdir (Root)9 if notos.path.exists (path):TenR=requests.get (URL) OneWith open (path,'WB') as F: A f.write (r.content) - f.close () - Print('file saved successfully') the Else: - Print('file already exists') - except: - Print('Crawl failed')
Climb a picture
I still don't understand this, and I didn't crawl out.
Python crawler Learning