import requests from lxml import etree # User-Agent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36 def body(): url = "https://mp.weixin.qq.com/s?__biz=MzIyMDM5NjE5Ng==&mid=2247494937&idx=3&sn=135161d92e11979bbe083d676afbb787&chksm=97ce02d2a0b98bc4dd58005d5a735f9aa5d45a370c0677d212c9dab6f39ffea635388af90b15&scene=21#wechat_redirect" header = {'User-Agent':'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'} respones = requests.get(url,headers=header) # print(respones) respones.encoding = "utf_8" html = respones.text obj = etree.HTML(html) obj_body = obj.xpath('//div[@class="rich_media_content "]//img/@data-src') del obj_body[0] del obj_body[-1] print(obj_body) y = len(obj_body) print(y) for i,ref in zip(obj_body,range(1,0+y)): r = requests.get(i) with open(r"F:day08人民日报微信图片\%s.png"%ref,"wb") as f: f.write(r.content) body()