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/zxvlP6xrMty_PKhuRYVeHA" 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_2 = obj.xpath('//div[@class="rich_media_content "]/p/img/@data-src') print(obj_2) for i in obj_2: r = requests.get(i) with open(r"F:day08人民日报微信图片\%s.doc"%i[-30:-20],"wb") as f: f.write(r.content) body()