- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
Windows 7版本Python36-32代码用途:网站解析
您能建议一下错误的可能原因是什么吗?我在函数“open”的开头和 (encoding = 'windows_1252', error = 'replace') 中包含了编码 utf-8它在其他网站的其他类似解析器中帮助了我,但对于这个不起作用
**一段代码:
# cycle through pages
for i in range (count):
s = str (i + 1)
print (s, end = '')
# make url
url = url1 + s + url2 + str (status) + url3
# get html file from server by url
r = requests.get (url)
# open file to save with full path to file name
name = path + 'upload' + s + '.html'
f = open (name, 'w', encoding = 'windows_1252', errors = 'replace')
# save url data to file
f.write (r.text)
# close file
f.close ()
# download files through the list
parseList (name, s + '.html')
print ()
return
错误文本:
Traceback (most recent call last):
File "C:\Users\u6030283\Desktop\FINAM\finam_parser_new.py", line 478, in <module>
parse('list', 'html', 'XS1272198265')
File "C:\Users\u6030283\Desktop\FINAM\finam_parser_new.py", line 262, in parse
f.write(r.text)
File "C:\Users\u6030283\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1251.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\x97' in position 206: character maps to <undefined>
最佳答案
更新:
问题不在于上面的代码(写入文件),而在于 parse()
或 parseList()
方法或读取文件。
替换以下内容
# in parseList(...)
text = open(url, 'r')
# and in parse(..)
text = open(path + file, 'r')
与
# in parseList(...)
text = open(url, 'r', encoding='windows_1252')
# and in parse(..)
text = open(path + file, 'r', encoding='windows_1252')
并且不要忘记将上述问题中的代码恢复到原始状态。
关于python - Unicode编码错误: 'charmap' codec can't encode character '\x97' in position 206: character maps to <undefined>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53701826/
我正在尝试使用 user guide 中的抓取示例运行 geb用于引入依赖项: $ cat my.groovy @Grapes([ @Grab("org.gebish:geb-core:0.9
我阅读了很多关于 opus-codec 的内容,但我不明白如何在我的示例 Java 应用程序中使用它。 是否有任何可用于 opus 的 .so 文件可以使用?如果没有,那么如何? 最佳答案 目前(在撰
我试图构建 Maven 项目, 每当我在命令行上运行“mvn clean install”时,都会出现以下错误: 无法解析项目 com.my_project:jar:0.0.1-SNAPSHOT 的依
我有一个项目需要 Lucene(4.3.0) 并添加以下依赖项:lucene-core,lucene-analyzers-common,lucene-queries,lucene-queryparse
我正在对 Controller 进行单元测试,目前我被服务(由 Controller 调用)中的“encodeAsJSON()”方法调用所困扰。 我得到了 MissingMethodException
无法弄清楚是什么原因导致 ' 名称为“Lucene42”的 org.apache.lucene.codecs.Codec 类型的 SPI 类不存在。您需要将支持此 SPI 的相应 JAR 文件添加到您
我想运行以下命令来使用 MongoDB Java 驱动程序创建用户, client = new MongoClient(mongoClientURI); MongoDatabase d
对于 lucene-core-5.5.2,我在 weblogic 服务器中遇到了问题 a。独立的搜索应用程序可以工作,但是当我部署为 WEB APP 时,它失败并出现以下错误 Exception ty
我的代码: DateTime dateTime = new DateTime(); BasicDBObject oldDoc = new BasicDBObject("email",email); B
我正在尝试在 Hibernate-ogm 中尝试 GridFS。这就是我的课 import org.hibernate.ogm.datastore.mongodb.type.GridFS; @Embe
我正在使用如下聚合: final List aggregations = new ArrayList<>(); Polygon polygon = new Polygon(new Po
我正在处理一个多模块 gradle 项目(12 个模块)。我继承了该项目,需要更新其中使用的一些库的版本。 我无法理解此错误的原因: ... 67 more Caused by: java.l
我正在使用 Java 学习 MongoDB。我正在尝试使用 Java 驱动程序将数据插入 MongoDB。我正在像 MongoDB 教程中一样进行插入,而且一切都很好。但是如果我想插入一个变量,当我运
我正在尝试打开并读取包含大量文本的 .txt 文件。下面是我的代码,我不知道如何解决这个问题。任何帮助将不胜感激。 file = input("Please enter a .txt file: ")
我使用 Arch Linux 和默认的 Python 3。我使用 Konsole 通过命令 pip install django-toolbelt 下载 django-toolbelt。名称: pip
我正在尝试使用 LibAV 解码 mpeg 视频文件。有两个术语我无法正确理解,镜框 和 数据包 . 按照我目前的理解,镜框 是未压缩的视频帧和 数据包是压缩帧。 问题 : 数据包有多个帧,对吗? 一
我正在查看计算机断层扫描 (CT) DICOM 图像。这些最初是未压缩的 DICOM 图像。我有这些 DICOM 图像的无损 J2K 压缩形式:传输语法 = 1.2.840.10008.1.2.4.9
如何安装通用编解码器?我已经下载了,但是我在网上搜索过,找不到这个问题的答案。我想使用 Base64 编码器和解码器。 还有 1 个问题,如果我的代码使用这个编解码器,其他尝试使用我的程序的用户是否也
本文整理了Java中loci.formats.codec.ZlibCodec类的一些代码示例,展示了ZlibCodec类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Ma
本文整理了Java中hivemall.utils.codec.ZigZagLEB128Codec类的一些代码示例,展示了ZigZagLEB128Codec类的具体用法。这些代码示例主要来源于Githu
我是一名优秀的程序员,十分优秀!