Python 反斜杠字符保留在最后一个字符串上
我是Python新手,在这个问题上很挣扎: 我正在使用Python和BeautifulSoup来抓取一个页面并获取url。打印url\u imagem时,它在控制台上显示,没有任何反斜杠转义字符,但在我的最终JSON上,它保留在字符串上Python 反斜杠字符保留在最后一个字符串上,python,json,python-3.x,encoding,beautifulsoup,Python,Json,Python 3.x,Encoding,Beautifulsoup,我是Python新手,在这个问题上很挣扎: 我正在使用Python和BeautifulSoup来抓取一个页面并获取url。打印url\u imagem时,它在控制台上显示,没有任何反斜杠转义字符,但在我的最终JSON上,它保留在字符串上 images_ = container_.find_all('div', class_='picture ng-tns-c3-1 ng-star-inserted') list_url = []
images_ = container_.find_all('div', class_='picture ng-tns-c3-1 ng-star-inserted')
list_url = []
for image in images_:
url_imagem_ = image.img.get('src')
list_url.append(url_imagem_)
url_imagem.append(list_url)
print(url_imagem)
数据帧到JSON:
with open('df.json', 'w', encoding='utf-8') as file:
df.to_json('../Files/myFile.json', force_ascii=False, orient='records')
提前感谢您的支持。您可以使用
lines=True
或通过replace('\','')
类似于(orient='records')的方式替换它。replace('\','')