想把爬取到的字符串写入图片详细信息中,只有部分正常写入,其他部分显示乱码,如下图黄框部分正常
from typing import Text
from bs4 import BeautifulSoup
import requests
from PIL import Image
import piexif
import lxml
from lxml import etree
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
'Accept-Language':'zh-CN'
}
page_respond = requests.get(url = 'https://www.gooood.cn/huahui-engineering-design-and-technological-innovation-center-china-by-huahui-group-we-studio.htm',headers = headers)
page_Soup = BeautifulSoup(page_respond .content, 'lxml')
page_spec_label = page_Soup.findAll('span', class_= 'label-text')
page_spec_data = page_Soup.findAll('div', class_= 'spec-data')
key_word = []
value_word = []
for i in page_spec_label:
# print(i.string)
key_word.append(i.string)
for j in page_spec_data:
s = j.find_all('a')
if len(s)>1:
l=';'.join([x.string for x in s])
elif len(s)==1:
l=s[0].string
else:
l=''
value_word.append(l)
address = 'https://www.gooood.cn/huahui-engineering-design-and-technological-innovation-center-china-by-huahui-group-we-studio.htm'
dict_word = dict(zip(key_word,value_word))
print(dict_word)
save_filename = 'F:/CodeWar/spider/exif/00.jpg'
im = Image.open(save_filename)
exif_dict = piexif.load(im.info["exif"])
exif_dict["0th"][piexif.ImageIFD.Artist] = address.encode()
exif_dict["0th"][piexif.ImageIFD.Software] = dict_word['材料'].encode()
exif_dict["0th"][piexif.ImageIFD.Copyright] = dict_word['设计公司'].encode()
exif_dict["0th"][piexif.ImageIFD.Make] = dict_word['标签'].encode()
exif_dict["0th"][piexif.ImageIFD.Model] = dict_word['分类'].encode()
exif_dict["0th"][piexif.ImageIFD.XPTitle] = dict_word['位置'].encode()
exif_dict["0th"][piexif.ImageIFD.XPSubject] = dict_word['类型'].encode()
exif_dict["0th"][piexif.ImageIFD.XPKeywords] = dict_word['设计公司'].encode()
exif_dict["0th"][piexif.ImageIFD.XPComment] = dict_word['位置'].encode()
exif_bytes = piexif.dump(exif_dict)
im.save(save_filename, exif=exif_bytes)
编码错误