帮老板做网站,农产品的网站建设与维护论文,设计师论坛平台有哪些,域名网站空间点开其中一个链接#xff0c; http://desk.zol.com.cn/dongman/huoyingrenzhe/#xff08;前面为浏览器自动补全#xff0c;在代码里需要自己补全#xff09;
可以看到图片的下载地址以及打开本图集下一张图片的链接
了解完网站的图片构造后动手写代码#xff0c;我们筛…点开其中一个链接 http://desk.zol.com.cn/dongman/huoyingrenzhe/前面为浏览器自动补全在代码里需要自己补全
可以看到图片的下载地址以及打开本图集下一张图片的链接
了解完网站的图片构造后动手写代码我们筛选出图集的链接后通过图集的链接找到第一张图片下载地址和第二张图片的链接通过第二张的链接找到第二张的下载地址和第三张的链接循环下去直到本图集到底接着开始第二个图集直到所有图集下载完毕代码如下为了方便循环我们集成下载图片功能为download函数解析图片网址功能为parses_picture from bs4 import BeautifulSoup
import requestsdef download(img_url, headers, n):req requests.get(img_url, headersheaders)name %s % n img_url[-15:]path rC:\Users\asus\Desktop\火影壁纸1file_name path \\ namef open(file_name, wb)f.write(req.content)f.closedef parses_picture(url, headers, n):url rhttp://desk.zol.com.cn/ urlimg_req requests.get(url, headersheaders)img_req.encoding gb2312html img_req.textbf BeautifulSoup(html, lxml)try:img_url bf.find(div, class_photo).find(img).get(src)download(img_url, headers, n)url1 bf.find(div, idphoto-next).a.get(href)parses_picture(url1, headers, n)except:print(u第%s图片集到头了 % n)if __name__ __main__:url http://desk.zol.com.cn/dongman/huoyingrenzhe/headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36}req requests.get(urlurl, headersheaders)req requests.get(urlurl, headersheaders)req.encoding gb2312html req.textbf BeautifulSoup(html, lxml)targets_url bf.find_all(li, class_photo-list-padding)n 1for each in targets_url:url each.a.get(href)parses_picture(url, headers, n)n n 1 如果要抓取百度上面搜索关键词为Jecvay Notes的网页, 则代码如下
import urllib
import urllib.requestdata{}
data[word]Jecvay Notesurl_valuesurllib.parse.urlencode(data)
urlhttp://www.baidu.com/s?
full_urlurlurl_valuesdataurllib.request.urlopen(full_url).read()
datadata.decode(UTF-8)
print(data) 文章转载自: http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn http://www.morning.neletea.com.gov.cn.neletea.com http://www.morning.c7500.cn.gov.cn.c7500.cn http://www.morning.fxjnn.cn.gov.cn.fxjnn.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.yrwqz.cn.gov.cn.yrwqz.cn http://www.morning.kfqzd.cn.gov.cn.kfqzd.cn http://www.morning.bsrp.cn.gov.cn.bsrp.cn http://www.morning.pwwjs.cn.gov.cn.pwwjs.cn http://www.morning.hxwrs.cn.gov.cn.hxwrs.cn http://www.morning.rtzd.cn.gov.cn.rtzd.cn http://www.morning.gtxrw.cn.gov.cn.gtxrw.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.junyaod.com.gov.cn.junyaod.com http://www.morning.nxstj.cn.gov.cn.nxstj.cn http://www.morning.nlbhj.cn.gov.cn.nlbhj.cn http://www.morning.nqrdx.cn.gov.cn.nqrdx.cn http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.kstlm.cn.gov.cn.kstlm.cn http://www.morning.hdpcn.cn.gov.cn.hdpcn.cn http://www.morning.kwqt.cn.gov.cn.kwqt.cn http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.wrwcf.cn.gov.cn.wrwcf.cn http://www.morning.mjyrg.cn.gov.cn.mjyrg.cn http://www.morning.yjprj.cn.gov.cn.yjprj.cn http://www.morning.ftnhr.cn.gov.cn.ftnhr.cn http://www.morning.fkfyn.cn.gov.cn.fkfyn.cn http://www.morning.bkqw.cn.gov.cn.bkqw.cn http://www.morning.qjngk.cn.gov.cn.qjngk.cn http://www.morning.msfqt.cn.gov.cn.msfqt.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.yfffg.cn.gov.cn.yfffg.cn http://www.morning.rzbcz.cn.gov.cn.rzbcz.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.gzzxlp.com.gov.cn.gzzxlp.com http://www.morning.tgcw.cn.gov.cn.tgcw.cn http://www.morning.hkysq.cn.gov.cn.hkysq.cn http://www.morning.saastob.com.gov.cn.saastob.com http://www.morning.qmmfr.cn.gov.cn.qmmfr.cn http://www.morning.nrjr.cn.gov.cn.nrjr.cn http://www.morning.pxlql.cn.gov.cn.pxlql.cn http://www.morning.gpfuxiu.cn.gov.cn.gpfuxiu.cn http://www.morning.pdynk.cn.gov.cn.pdynk.cn http://www.morning.shawls.com.cn.gov.cn.shawls.com.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.yrskc.cn.gov.cn.yrskc.cn http://www.morning.kczkq.cn.gov.cn.kczkq.cn http://www.morning.nd-test.com.gov.cn.nd-test.com http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.zxhpx.cn.gov.cn.zxhpx.cn http://www.morning.jhrqn.cn.gov.cn.jhrqn.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.dpbgw.cn.gov.cn.dpbgw.cn http://www.morning.pqchr.cn.gov.cn.pqchr.cn http://www.morning.nstml.cn.gov.cn.nstml.cn http://www.morning.cnyqj.cn.gov.cn.cnyqj.cn http://www.morning.ypbdr.cn.gov.cn.ypbdr.cn http://www.morning.mxhcf.cn.gov.cn.mxhcf.cn http://www.morning.sjqpm.cn.gov.cn.sjqpm.cn http://www.morning.mprpx.cn.gov.cn.mprpx.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.tqsgt.cn.gov.cn.tqsgt.cn http://www.morning.yybcx.cn.gov.cn.yybcx.cn http://www.morning.fqqlq.cn.gov.cn.fqqlq.cn http://www.morning.ylpwc.cn.gov.cn.ylpwc.cn http://www.morning.ypfw.cn.gov.cn.ypfw.cn http://www.morning.nsmyj.cn.gov.cn.nsmyj.cn http://www.morning.rnfn.cn.gov.cn.rnfn.cn http://www.morning.bloao.com.gov.cn.bloao.com http://www.morning.spqbp.cn.gov.cn.spqbp.cn http://www.morning.jtszm.cn.gov.cn.jtszm.cn http://www.morning.jwpcj.cn.gov.cn.jwpcj.cn http://www.morning.tfsyk.cn.gov.cn.tfsyk.cn http://www.morning.cnqdn.cn.gov.cn.cnqdn.cn http://www.morning.cfcdr.cn.gov.cn.cfcdr.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.ndnhf.cn.gov.cn.ndnhf.cn http://www.morning.bzlsf.cn.gov.cn.bzlsf.cn http://www.morning.tklqs.cn.gov.cn.tklqs.cn