当前位置:   article > 正文

零基础用python爬取百度图片_爬取百度图片代码

爬取百度图片代码
1.导入库

分别导入re os requests

  1. import os
  2. import re
  3. import requests
'
运行

2.获取网站源代码

  1. def get_html(url,headers,params):
  2. response = requests.get(url,headers=headers,params=params)
  3. #源代码的编写方式
  4. response.encoding = "utf-8"
  5. if response.status_code == 200:
  6. return response.text
  7. else:
  8. print("错误")
'
运行

3.提取图片源地址

  1. def parse_pic_url(html):
  2. result = re.findall('thumbURL":"(.*?)"',html,re.S)
  3. return result
'
运行
4.获取图片二进制码
  1. def get_pic_content(url):
  2. response = requests.get(url)
  3. return response.content
  4. def save_pic(fold_name,content,pic_name):
  5. with open(fold_name + "/" + str(pic_name)+".jpg","wb") as f:
  6. f.write(content)
  7. f.close()

5.定义main函数调用get_html函数,先看详细代码,

  1. def main():
  2. pic_name = 7777
  3. # 构建循环
  4. for i in range(2):
  5. url="https://image.baidu.com/search/acjson?tn=resulttagjson&logid=10559289060731775977&ie=utf-8&fr=ala&word=%E5%A4%A7%E7%86%8A%E7%8C%AB%E5%8F%AF%E7%88%B1&ipn=r&fm=index&pos=history&queryWord=%E5%A4%A7%E7%86%8A%E7%8C%AB%E5%8F%AF%E7%88%B1&cl=2&lm=-1&oe=utf-8&adpicid=&st=&z=&ic=&hd=&latest=&copyright=&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&expermode=&nojc=&isAsync=true&pn=90&rn=30&itg=1&gsm=5a&1695868895378="
  6. headers={
  7. "Accept": "text/plain, */*; q=0.01",
  8. "Accept-Encoding": "gzip, deflate",
  9. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  10. "Cache-Control": "max-age=0",
  11. "Connection": "keep-alive",
  12. "Cookie": "BDqhfp=%E5%A4%A7%E7%86%8A%E7%8C%AB%26%26NaN-1undefined%26%261428%26%263; MCITY=-%3A; BDUSS=WM5MWpGWndPV2NRSmMxbHM4dDEyajYwUGQ3MFZSclVnb0RjSlNRT1VlMUstYkJrSVFBQUFBJCQAAAAAABAAAAEAAACk79r6b2dmZ2doAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEpsiWRKbIlke; BDUSS_BFESS=WM5MWpGWndPV2NRSmMxbHM4dDEyajYwUGQ3MFZSclVnb0RjSlNRT1VlMUstYkJrSVFBQUFBJCQAAAAAABAAAAEAAACk79r6b2dmZ2doAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEpsiWRKbIlke; BAIDUID=15D8AF7362A233007142B2B2ACCE80C2:FG=1; H_WISE_SIDS=234020_110085_268708_259642_256154_269782_269832_269904_270597_271022_271170_267659_271319_271269_270102_271812_272226_270055_272278_273119_273301_272641_273736_274078_269609_273917_273044_272560_197096_179345_274765_274761_273982_275069_272801_275147; PSTM=1695112087; BIDUPSID=E9DD811BDB5CB67FE5A3F85BAFCEEF52; indexPageSugList=%5B%22%E4%BA%8C%E6%AC%A1%E5%85%83%E5%9B%BE%E7%89%87%22%2C%22%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87%22%2C%22%E6%B2%99%E5%8F%91log%22%2C%22%E7%8C%AB%22%2C%22%E7%BD%91%E9%A1%B5%E8%83%8C%E6%99%AF%E5%9B%BE%22%2C%22%E8%83%8C%E6%99%AFbmp%22%2C%22%E5%8D%8A%E5%AF%BC%E4%BD%93%22%2C%22%E5%9C%BA%E6%95%88%E5%BA%94%E7%AE%A1%E5%9B%BE%E7%89%87%22%2C%22%E6%99%B6%E9%97%B8%E7%AE%A1%E5%9B%BE%E7%89%87%22%5D; H_PS_PSSID=26350; BAIDUID_BFESS=15D8AF7362A233007142B2B2ACCE80C2:FG=1; ZFY=aUZeZY4WXw0POTirA:BtrNIadn49in1kQ7bqBYWeWk94:C; delPer=1; PSINO=7; BDORZ=FFFB88E999055A3F8A630C64834BD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ala; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; ab_sr=1.0.1_NmY0ZmI3NmRlNzYzMmI2MTEyMTVmZmJhM2QzMTI5ZjUyYTU1OWIwMmQzZjNmNjE4NmNlMTIyZTcxMzg4N2U1ZGM1ZTg4OGNmMDg2YjJmMjljMWIwMzEwZTk4ZjBmYWYxMjg2ZmI0NGE5YjljOTAwNTJlN2ZiNjNmYzBiMzY1MzIxN2FlNzE0MzE3ZmE3MGZjNzQyMTU2ZGQ1ZDNhYTM0Nw==",
  13. "Host": "image.baidu.com",
  14. "Referer": "https: // image.baidu.com / search / index?tn = baiduimage & ct = 201326592 & lm = -1 & cl = 2 & ie = gb18030 & word = % B4 % F3 % D0 % DC % C3 % A8 & fr = ala & ala = 1 & alatpl = normal & pos = 0 & dyTabStr = MTEsMCwxLDYsMyw0LDUsMiw4LDcsOQ%3D%3D",
  15. "sec-ch-ua": '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  16. "sec-ch-ua-mobile": "?0",
  17. "sec-ch-ua-platform": '"Windows"',
  18. "Sec-Fetch-Dest": "empty",
  19. "Sec-Fetch-Mode": "cors",
  20. "Sec-Fetch-Site": "same-origin",
  21. "Sec-Fetch-User": "?1",
  22. "Upgrade-Insecure-Requests": "1",
  23. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57",
  24. }
  25. params={
  26. "logid":" 10545277816764792645",
  27. "ipn":" rj",
  28. "ct":" 201326592",
  29. "fp":" result",
  30. "fr":" ala",
  31. "word":" 大熊猫",
  32. "queryWord":" 大熊猫",
  33. "cl":" 2",
  34. "lm":" -1",
  35. "ie":" utf-8",
  36. "oe":" utf-8",
  37. "pn":str(int(i+1)*30),
  38. "rn":" 30",
  39. "gsm":" 3c",
  40. }
'
运行

(1)首先打开百度图片,找到自己需要爬取的图片,例爬取动漫头像

(2)鼠标单击右键或者用F12打开开发者模式,例

(3)找到网络单元下的Fetch/XHR

(4)用鼠标滑动网页,可以明显看到网络单元下出现开头名为acjson的数据,点击其中一个

在标头能看到一个请求URL,这个是我们所需要的网址

(5)继续往下滑动,可以看到有一个请求标头,这是我们headers里面的所有内容

将其所有复制,在复制前可以用""" """注释后进行修改,然后修改:":"前后的文本都要加双引号"",文本中有双引号的就加单引号'',改成如上代码的形式

(6)接下来就是params的内容,该内容在负载里面

如下是完整代码

  1. #导入库
  2. import re
  3. import os
  4. import requests
  5. #获取网站源代码
  6. def get_html(url,headers,params):
  7. response = requests.get(url,headers=headers,params=params)
  8. #设置源代码的编码方式
  9. response.encoding="utf-8"
  10. if response.status_code == 200:
  11. return response.text
  12. else:
  13. print("网站源码获取错误")
  14. #提取图片源代码
  15. def parse_pic_url(html):
  16. result = re.findall('thumbURL":"(.*?)"',html,re.S)
  17. return result
  18. #获取二进制码
  19. def get_pic_content(url):
  20. response = requests.get(url)
  21. return response.content
  22. #保存图片
  23. def save_pic(content,pic_name):
  24. with open("大熊猫/"+str(pic_name)+".jpg","wb") as f:
  25. f.write(content)
  26. f.close()
  27. #定义main函数调用get_html函数
  28. def main():
  29. pic_name = 7777
  30. # 构建循环
  31. for i in range(2):
  32. url="https://image.baidu.com/search/acjson?tn=resulttagjson&logid=10559289060731775977&ie=utf-8&fr=ala&word=%E5%A4%A7%E7%86%8A%E7%8C%AB%E5%8F%AF%E7%88%B1&ipn=r&fm=index&pos=history&queryWord=%E5%A4%A7%E7%86%8A%E7%8C%AB%E5%8F%AF%E7%88%B1&cl=2&lm=-1&oe=utf-8&adpicid=&st=&z=&ic=&hd=&latest=&copyright=&s=&se=&tab=&width=&height=&face=&istype=&qc=&nc=&expermode=&nojc=&isAsync=true&pn=90&rn=30&itg=1&gsm=5a&1695868895378="
  33. headers={
  34. "Accept": "text/plain, */*; q=0.01",
  35. "Accept-Encoding": "gzip, deflate",
  36. "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
  37. "Cache-Control": "max-age=0",
  38. "Connection": "keep-alive",
  39. "Cookie": "BDqhfp=%E5%A4%A7%E7%86%8A%E7%8C%AB%26%26NaN-1undefined%26%261428%26%263; MCITY=-%3A; BDUSS=WM5MWpGWndPV2NRSmMxbHM4dDEyajYwUGQ3MFZSclVnb0RjSlNRT1VlMUstYkJrSVFBQUFBJCQAAAAAABAAAAEAAACk79r6b2dmZ2doAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEpsiWRKbIlke; BDUSS_BFESS=WM5MWpGWndPV2NRSmMxbHM4dDEyajYwUGQ3MFZSclVnb0RjSlNRT1VlMUstYkJrSVFBQUFBJCQAAAAAABAAAAEAAACk79r6b2dmZ2doAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEpsiWRKbIlke; BAIDUID=15D8AF7362A233007142B2B2ACCE80C2:FG=1; H_WISE_SIDS=234020_110085_268708_259642_256154_269782_269832_269904_270597_271022_271170_267659_271319_271269_270102_271812_272226_270055_272278_273119_273301_272641_273736_274078_269609_273917_273044_272560_197096_179345_274765_274761_273982_275069_272801_275147; PSTM=1695112087; BIDUPSID=E9DD811BDB5CB67FE5A3F85BAFCEEF52; indexPageSugList=%5B%22%E4%BA%8C%E6%AC%A1%E5%85%83%E5%9B%BE%E7%89%87%22%2C%22%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87%22%2C%22%E6%B2%99%E5%8F%91log%22%2C%22%E7%8C%AB%22%2C%22%E7%BD%91%E9%A1%B5%E8%83%8C%E6%99%AF%E5%9B%BE%22%2C%22%E8%83%8C%E6%99%AFbmp%22%2C%22%E5%8D%8A%E5%AF%BC%E4%BD%93%22%2C%22%E5%9C%BA%E6%95%88%E5%BA%94%E7%AE%A1%E5%9B%BE%E7%89%87%22%2C%22%E6%99%B6%E9%97%B8%E7%AE%A1%E5%9B%BE%E7%89%87%22%5D; H_PS_PSSID=26350; BAIDUID_BFESS=15D8AF7362A233007142B2B2ACCE80C2:FG=1; ZFY=aUZeZY4WXw0POTirA:BtrNIadn49in1kQ7bqBYWeWk94:C; delPer=1; PSINO=7; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; BA_HECTOR=842k24a0800h250g040k250d1ih9kv01o; BCLID=12000947481008567227; BCLID_BFESS=12000947481008567227; BDSFRCVID=2p8OJexroG0ZmSbqQQGl-hLfHuweG7bTDYrEOwXPsp3LGJLVFakFEG0Pts1-dEu-S2OOogKKXgOTHw0F_2uxOjjg8UtVJeC6EG0Ptf8g0M5; BDSFRCVID_BFESS=2p8OJexroG0ZmSbqQQGl-hLfHuweG7bTDYrEOwXPsp3LGJLVFakFEG0Pts1-dEu-S2OOogKKXgOTHw0F_2uxOjjg8UtVJeC6EG0Ptf8g0M5; H_BDCLCKID_SF=tRAOoC_-tDvDqTrP-trf5DCShUFsQh4JB2Q-XPoO3KJADfOPKfvnQjJDM-vhBnQf5mkf3fbgy4op8P3y0bb2DUA1y4vp0toW3eTxoUJ2-KDVeh5Gqq-KXU4ebPRiXPb9QgbfopQ7tt5W8ncFbT7l5hKpbt-q0x-jLTnhVn0MBCK0hD89DjKKD6PVKgTa54cbb4o2WbCQ0f3M8pcN2b5oQT8lhJbabx70tgCLBpRDWP5beq06-lOUWJDkXpJvQnJjt2JxaqRC3JjOsl5jDh3MKToDb-oteltHB2Oy0hvcyn3cShn6DMjrDRLbXU6BK5vPbNcZ0l8K3l02V-bIe-t2XjQhDH-OJ6DHtJ3aQ5rtKRTffjrnhPF3QRtvXP6-hnjy3bRzWxOt-lREhxFzMMvtybLWbttf5q3Ry6r42-39LPO2hpRjyxv4Q4_fQ4oxJpOJ-bCL0p5aHx8K8p7vbURvW--g3-7fJU5dtjTO2bc_5KnlfMQ_bf--QfbQ0hOhqP-jBRIEoC8ytC_KhCvPKITD-tF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3h4t9XU6q2bDeQN3z2lJa-G6IKb4E2pRtO-56bftb-l0vWq54WbbvLT7johRTWqR4sRjcQxonDh83KNLLKUQtHGAH2h7O5hvvob3O3M7bDMKmDloOW-TB5bbPLUQF5l8-sq0x0bOte-bQXH_E5bj2qRFDoIKb3D; BDRCVFR[dG2JNJb_ajR]=mk3SLVN4HKm; userFrom=ala; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; ab_sr=1.0.1_NmY0ZmI3NmRlNzYzMmI2MTEyMTVmZmJhM2QzMTI5ZjUyYTU1OWIwMmQzZjNmNjE4NmNlMTIyZTcxMzg4N2U1ZGM1ZTg4OGNmMDg2YjJmMjljMWIwMzEwZTk4ZjBmYWYxMjg2ZmI0NGE5YjljOTAwNTJlN2ZiNjNmYzBiMzY1MzIxN2FlNzE0MzE3ZmE3MGZjNzQyMTU2ZGQ1ZDNhYTM0Nw==",
  40. "Host": "image.baidu.com",
  41. "Referer": "https: // image.baidu.com / search / index?tn = baiduimage & ct = 201326592 & lm = -1 & cl = 2 & ie = gb18030 & word = % B4 % F3 % D0 % DC % C3 % A8 & fr = ala & ala = 1 & alatpl = normal & pos = 0 & dyTabStr = MTEsMCwxLDYsMyw0LDUsMiw4LDcsOQ%3D%3D",
  42. "sec-ch-ua": '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  43. "sec-ch-ua-mobile": "?0",
  44. "sec-ch-ua-platform": '"Windows"',
  45. "Sec-Fetch-Dest": "empty",
  46. "Sec-Fetch-Mode": "cors",
  47. "Sec-Fetch-Site": "same-origin",
  48. "Sec-Fetch-User": "?1",
  49. "Upgrade-Insecure-Requests": "1",
  50. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57",
  51. }
  52. params={
  53. "logid":" 10545277816764792645",
  54. "ipn":" rj",
  55. "ct":" 201326592",
  56. "fp":" result",
  57. "fr":" ala",
  58. "word":" 大熊猫",
  59. "queryWord":" 大熊猫",
  60. "cl":" 2",
  61. "lm":" -1",
  62. "ie":" utf-8",
  63. "oe":" utf-8",
  64. "pn":str(int(i+1)*30),
  65. "rn":" 30",
  66. "gsm":" 3c",
  67. }
  68. html = get_html(url,headers,params)
  69. #print(html)
  70. result = parse_pic_url(html)
  71. #定义图片名字
  72. # pic_name = 0
  73. for item in result:
  74. #调用函数,获取二进制源码
  75. pic_content = get_pic_content(item)
  76. # print(pic_content)
  77. # 调用函数,保存图片
  78. save_pic(pic_content,pic_name)
  79. pic_name +=1
  80. print("正在保存第"+str(pic_name))
  81. #执行main函数
  82. if __name__ == '__main__':
  83. main()
'
运行

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/801062
推荐阅读
相关标签
  

闽ICP备14008679号