Python 3.x 使用bs4在excel中删除保加利亚语文本时出现问题
我正试图抓取一个包含保加利亚文字的网站。它已成功地刮取,但当我将其存储到CSV文件中时,它不可读。请参阅下面的代码和图片,以更好地了解我的问题Python 3.x 使用bs4在excel中删除保加利亚语文本时出现问题,python-3.x,web-scraping,beautifulsoup,export-to-csv,Python 3.x,Web Scraping,Beautifulsoup,Export To Csv,我正试图抓取一个包含保加利亚文字的网站。它已成功地刮取,但当我将其存储到CSV文件中时,它不可读。请参阅下面的代码和图片,以更好地了解我的问题 res = requests.get('https://m.mobile.bg/results? pubtype=1&marka=Toyota¤cy=%D0%BB%D0%B2.&sort=1&nup=0~1') soup = bs4.BeautifulSoup(res.text, 'lxml') f
res = requests.get('https://m.mobile.bg/results?
pubtype=1&marka=Toyota¤cy=%D0%BB%D0%B2.&sort=1&nup=0~1')
soup = bs4.BeautifulSoup(res.text, 'lxml')
file = open('cars.csv', 'w')
writer = csv.writer(file)
# write title row
writer.writerow(['Car_Make', 'Price', 'info', 'date'])
for i in soup.select('.listItem'):
car_make = i.find('div', attrs = {"class":"title"})
arr = i.text
print(arr)
writer.writerow([arr.encode('utf-8')])
file.close()
导入请求
导入csv
从bs4导入BeautifulSoup
def主(url):
参数={
“pubtype”:“1”,
“marka”:“丰田”,
“货币”:“аа”,
“排序”:“1”,
“nup”:“0~1”
}
r=requests.get(url,params=params)
soup=BeautifulSoup(r.text'lxml')
将open('d.csv','w',newline='',encoding='utf-8-sig')作为f:
writer=csv.writer(f)
writer.writerows([list(x.strings))
用于汤中的x。选择('.listItem.TOPitem'))
主要('https://m.mobile.bg/results')
输出:
如果支持utf-8-sig不能解决问题,请尝试使用utf-8-sig。非常感谢,@barny。我不知道术语,因为这是我第一次做这样的任务。谢谢你澄清术语。