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/BzDw9nWASnOkmgWcfl6MuA" 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] print(obj_body) ret = len(obj_body) print(ret) obj_titer = obj.xpath('//div[@class="rich_media_content "]//strong//span/text()') y = [] for i in obj_titer: res = i.strip('xa0xa0☟') y.append(res) print(y) for i,ref in zip(obj_body,y): r = requests.get(i) with open(r"F:day08人民日报微信图片\%s.gif"%ref,"wb") as f: f.write(r.content) body()