- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 lxml.html 来解析 html 文件并从页面中获取文本。现在我有一个字符串,它有一个字符 '
例如 Florian's
因此,在打印输出时我得到了回溯
parent_link_id_text = parent_link_id.xpath('./td[@width="400"]/text()')
print (SGS_Mid[0]+";"+"External"+";"+str(link_id_num[0])+";"+parent_link_id_text[0]+";"+parent_link_link[0], file = log_file_1)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 56-58: ordinal not in range(128)
然后我试了一下
print (SGS_Mid[0]+";"+"PublicFreeUrl"+";"+str(link_id_num[0])+";"+unicode(parent_link_id_text[0],"utf-8")+";"+parent_link_link[0], file = log_file_1)
然后我得到一个回溯:
TypeError: decoding Unicode is not supported
如何通过打印带有 unicode 字符的字符串来解决这个问题?
最佳答案
不确定这是否是您问题的解决方案,但也许它会引导您朝着正确的方向前进。
在没有看到您必须实际获取数据的代码的情况下,我将推测并以编程方式猜测如何解决您的问题。
请看下面的代码:
import lxml.html as lh
import urllib2
url = 'http://loremipsum.net/about.html'
doc = lh.parse(urllib2.urlopen(url))
value = doc.xpath('//p/strong/text()')[0]
print value
打印结果:
What is 'lorem ipsum'?
通过阅读 lorem ipsum 站点上的关于页面,您可以看到返回的文本中确实包含 '。
我希望这能帮助您朝着正确的方向前进。
关于python - 类型错误 : decoding Unicode is not supported python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17701130/
我得到了一些有趣的结果,试图辨别使用 Encode::decode("utf8", $var) 之间的区别。和 utf8::decode($var) .我已经发现,在一个变量上多次调用前者最终会导致错
我尝试使用 FlushedInputStream :Android decoder->decode returned false for Bitmap download 但没有任何变化,因为我使用:B
我有一小部分代码: from pyasn1.type import univ from pyasn1.codec.ber import decoder decoder.decode(binary_fi
这个问题在这里已经有了答案: Instantiated optional variable shows as nil in Xcode debugger (2 个答案) 关闭 2 年前。 在 Swi
我在 Playground 中有以下示例代码。如果结果符合 Decodable 协议(protocol),我想解码网络请求的结果。 知道为什么这段代码不起作用吗? protocol APIReques
我正在尝试使用 imagecreatefromwebp() 将 webp 文件转换为 JPEG,但不幸的是,它向我发出警告:警告:imagecreatefromwebp():WebP 解码:无法解码输
我试图覆盖 JSONDecoder 解码数据的方式。 我尝试了以下方法: struct Response : Decodable { init(from decoder: Decoder) t
ACTIVATE_THIS = """ eJx1UsGOnDAMvecrIlYriDRlKvU20h5aaY+teuilGo1QALO4CwlKAjP8fe1QGGalRoLEefbzs+Mk Sb7
我正在尝试使用 swift 4 来解析本地 json 文件: { "success": true, "lastId": null, "hasMore": false,
我的代码有问题。 我正在尝试使用ExtJS和Codeigniter制作上传文件格式。 这是我的下面的代码, Ext.require([ 'Ext.form.field.File',
我有一些遗留代码正在调用 sun.net.www.ParseUtil.decode()。我想避免调用供应商特定的函数,所以我想用其他东西替换调用。 我可以使用 java.net.URLDecoder.
使用 Sonatype Nexus,我仅在访问 /nexus/#admin/support/status 时收到此错误消息. Ext.JSON.decode(): You're trying to d
我正在学习 Elm,让我感到困惑的一件事是“Json.Decode.succeed”。根据docs succeed : a -> Decoder a Ignore the JSON and produ
有什么区别 URLDecoder.decode(String s) 和 URLDecoder.decode(String s, String enc) 我有一个 cookie 值,例如 val=%22
使用 Google Apps 脚本,我想解码 HTML,例如: Some text & text ¢ 存储为: Some text & text ¢ 所以,类似的问题:How t
我正在对带有字幕的视频进行编码,但出现错误“解码的字幕文本中的 UTF-8 无效;可能缺少 -sub_charenc 选项。解码流时出错”,但视频还是编码了。忽略此错误的后果是什么?谷歌搜索显示一个人
我有如下代码: cn_bytes = [157, 188, 156] cn_str = "" clen = len(cn_bytes) count = int(clen / 3) for x in r
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
This script give you a decoded listing from an encoded file. Supports *,je, ,vbe, .asp, .hta, .htm,
telnet客户端响应如何解码 我认为这是一个特定的响应,因为所有思科服务器都有相同的响应.这段文字的名称是什么,我如何解密它 '\xff\xfb\x01\xff\xfb\x03\xff\xfd\x1
我是一名优秀的程序员,十分优秀!