从网页复制文本并将其粘贴到txt文件或csv文件中 [英] Copy and paste text from webpage to txt file or csv file

查看:54
本文介绍了从网页复制文本并将其粘贴到txt文件或csv文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网页中复制文本并将其粘贴到文本文件中.没什么花哨的,但我似乎无法弄清楚该怎么做或在网上找到任何可行的方法.

I am trying to copy text from a webpage and paste it into a text file. Nothing too fancy but I can't seem to figure out how to do it or find anything online that works.

import requests

url = 'https://seekingalpha.com/article/4166013-t-t-q1-2018-results-earnings-call-transcript?part=single'
data = requests.get(url)

with open('file.txt','w') as out_f:
   out_f.write(data.text)

我收到一个Unicode编码错误\ ufeff.有没有一种方法可以全部选择,复制然后粘贴到文本文件中?似乎很简单,但无法弄清楚.

I get a unicode encode error, \ufeff. Is there a way to just select all, copy, and then paste into a text file? Seems so simple but can't figure it out.

先谢谢您!

推荐答案

尝试将文本编码为utf-8

Try encoding your text as utf-8

import requests

url = 'https://seekingalpha.com/article/4166013-t-t-q1-2018-results-earnings-call-transcript?part=single'
data = requests.get(url)

with open('file.txt','w') as out_f:
   out_f.write(data.text.encode('utf-8'))

这篇关于从网页复制文本并将其粘贴到txt文件或csv文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆