【发布时间】:2019-02-18 14:38:27
【问题描述】:
如果我有一个如下的html,并且我使用beautiful soup 来解析它,我如何访问<head> 元素之前的行。
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
例如,访问 head 元素的标准方法是 soup.head 或 body 是 soup.body。我认为这是因为 head 和 body 都是标准标签。
有没有办法访问<head>之前的元素?
【问题讨论】:
-
我建议在 BS 上使用 XML 解析器
标签: python beautifulsoup