Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 反斜杠字符保留在最后一个字符串上_Python_Json_Python 3.x_Encoding_Beautifulsoup - Fatal编程技术网

Python 反斜杠字符保留在最后一个字符串上

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 = []

我是Python新手,在这个问题上很挣扎:

我正在使用Python和BeautifulSoup来抓取一个页面并获取url。打印url\u imagem时,它在控制台上显示,没有任何反斜杠转义字符,但在我的最终JSON上,它保留在字符串上

                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('\','')