karlxu
V2EX  ›  问与答

请教个 python2.7 读取 html 文件的编码问题

  •  
  •   karlxu · Jun 25, 2018 · 1850 views
    This topic created in 3080 days ago, the information mentioned may be changed or developed.

    截图是个 html 文件,编码是:<meta http-equiv="Content-Type" content="text/html; charset=unicode">
    python 想查找有没有 table class 关键字:

    但是找不到 table class,感觉是编码的问题,我也试过中间加上空格,也找不到。
    代码最开头已经加了:

    应该怎么写才能正确读到?谢谢!
    5 replies  •  2018-06-26 09:32:14 +08:00
    ThirdFlame
    ThirdFlame
    Jun 25, 2018
    1
    我觉得里面有空格吧。 用 16 进制的方式看一看 到底是什么内容。
    另外复制 查找也不行么?
    karlxu
    karlxu
    OP
    Jun 25, 2018
    2
    @ThirdFlame 在 notepad++里展示和查找是正常的,没有空格,就是 print 的时候发现有空格
    msg7086
    msg7086
    Jun 25, 2018
    3
    charset=unicode

    你为什么要用 utf-8 去读?又不是 charset=utf-8。
    aiver
    aiver
    Jun 26, 2018
    4
    如果是标准 HTML 文件,用 BS 库打印了看看。另外,楼上说的对,unicode 为什么用 utf-8 解析啊
    karlxu
    karlxu
    OP
    Jun 26, 2018 via iPhone
    5
    @msg7086
    @aiver
    一开始不知道是 unicode,这个是 beyond compare 生成的 html,对比 2 个 Excel
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1115 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:04 · PVG 02:04 · LAX 10:04 · JFK 13:04
    ♥ Do have faith in what you're doing.