编码/看不到字母
我正在打开数组中的链接并从中抓取数据,并将其放入数组中,然后将其转换为 csv 文件。当我在 PyCharm IDE 中打开完成的 csv 文件时,我正确地看到了我的语言字母,例如 ą、ę、ė、į、š、ų、ū,但是当我从桌面打开该 csv 文件时,我的文本已损坏,如下所示“< GrÄ â�ti atgal”。我尝试使用 UTF-8 编码保存 csv 文件,但没有帮助。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import pandas as pd
import csv
import urllib.request
from bs4 import BeautifulSoup
import numpy as np
with open('neduplikuotas.csv', newline='') as csvfile:
data1 = list(csv.reader(csvfile))
data = [''.join(ele) for ele in data1]
i = 1
test = data[3550:]
array = []
for element in test:
array.append(i)
html = urllib.request.urlopen(element)
htmlParse = BeautifulSoup(html, 'html.parser')
for paragraph in htmlParse.find_all("p"):
array.append(paragraph.get_text())
i=i+1
df = pd.DataFrame(array)
df.to_csv('viskas5.csv')
I'm opening links from array and scraping data from them which I put into array and then convert it into csv file. When i open that finished csv file in PyCharm IDE i see my language letters such as ą,ę,ė,į,š,ų,ū correctly but when i open that csv file from desktop my text is corrupted like this "< Grįžti atgal". I tried saving csv file with encoding UTF-8 but it didn't help.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import pandas as pd
import csv
import urllib.request
from bs4 import BeautifulSoup
import numpy as np
with open('neduplikuotas.csv', newline='') as csvfile:
data1 = list(csv.reader(csvfile))
data = [''.join(ele) for ele in data1]
i = 1
test = data[3550:]
array = []
for element in test:
array.append(i)
html = urllib.request.urlopen(element)
htmlParse = BeautifulSoup(html, 'html.parser')
for paragraph in htmlParse.find_all("p"):
array.append(paragraph.get_text())
i=i+1
df = pd.DataFrame(array)
df.to_csv('viskas5.csv')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论