网易lofter问题bug太多了,估计会倒闭,所以从现在赶快抢救搬家还来得及,
一、从lofter把博文数据保存到本地。
1.
2.
至此,导出的是所有博文的xml数据,很多图片还没拖下来,用程序下载当然很方便了,不会弄的可以联系我付费帮忙redstone-cold@163.com,价格50元起
from bs4 import BeautifulSoup
import re
import urllib.parse
import requests
import os
def writeImg(imgUrl):
imgReply = requests.get(imgUrl) # stream=True,
# print(r.headers) # r.text, r.history, r.text,lastChild
with open('{}'.format(os.path.basename(urllib.parse.urlparse(imgUrl).path)), "ab") as file:
file.write(imgReply.content)
xml = open(r'E:\LOFTER\LOFTER.xml', encoding="utf8").read()
soup = BeautifulSoup(xml, 'xml') # 必须以xml形式解析,否则不能识别photoLinks tag
imgs = soup.find_all('img', src=True) # 有的img没有src
for img in imgs:
# print(img['src'])
writeImg(img['src'])
photoLinksTags = soup.findAll('photoLinks')
# #re.findall(r'"orign": ".+?"', xml)
# print(eval(imgs[-2].string)) # [0] imgs[-2].string,
for photoLinksTag in photoLinksTags:
for photoItem in eval(photoLinksTag.string): # photoLinksTag里包含一系列photoItems,以dict方式展现
# print(photoItem["orign"])
writeImg(photoItem["orign"])
二、搬家到其它博客平台,诸如:新浪微博、新浪博客、WordPress、blogger(Blogspot)、博客园cnblogs、简书、网易博客、tumblr、豆瓣,这个需要具体抠这些平台的API了,只能具体平台具体解决了。