Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python美化xml定义中的双问号_Python_Xml_Xhtml_Beautifulsoup - Fatal编程技术网

Python美化xml定义中的双问号

Python美化xml定义中的双问号,python,xml,xhtml,beautifulsoup,Python,Xml,Xhtml,Beautifulsoup,我认为这一定是一个错误,所以我发布了一个错误报告。 另一方面,我可能遗漏了一些东西,所以我需要再次查看代码 问题是,当我使用.xhtml文件的内容初始化BeautifulSoup时,xml定义在它的末尾会有两个问号 你能重现这个问题吗?有办法避免吗?我是否缺少一个函数、一个方法、一个参数或其他什么 Edit0:这是python 2.x上的BeautifulSoup4 Edit1:为什么要投否决票 问题是: <?xml version="1.0" encoding="UTF-8"??>

我认为这一定是一个错误,所以我发布了一个错误报告。 另一方面,我可能遗漏了一些东西,所以我需要再次查看代码

问题是,当我使用.xhtml文件的内容初始化BeautifulSoup时,xml定义在它的末尾会有两个问号

你能重现这个问题吗?有办法避免吗?我是否缺少一个函数、一个方法、一个参数或其他什么

Edit0:这是python 2.x上的BeautifulSoup4

Edit1:为什么要投否决票


问题是:

<?xml version="1.0" encoding="UTF-8"??>

终端输出:

>>> from bs4 import BeautifulSoup as bs
>>> with open('example.xhtml', 'r') as f:
...     txt = f.read()
...     soup = bs(txt)
... 
>>> print txt
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8"/>
    </head>
    <body>
    </body>
</html>

>>> print soup
<?xml version="1.0" encoding="UTF-8"??>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
</head>
<body>
</body>
</html>
>>从bs4导入BeautifulSoup作为bs
>>>使用open('example.xhtml','r')作为f:
...     txt=f.read()
...     汤=bs(txt)
... 
>>>打印文本
>>>印花汤

在example.xhtml文件中使用“txt”中变量的内容,我无法重现Python2.7和相应的BeautifulSoup模块(不是bs4)的问题。对我来说很好很漂亮

>>> soup = BeautifulSoup.BeautifulSoup(txt)
>>> print soup
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>
>>soup=beautifulsou.beautifulsou(txt)
>>>印花汤

你遇到的问题是什么,比如你的最终目标是什么,也许somoone可以在example.xhtml文件中使用“txt”中变量的内容来建议解决方法。我无法用Python2.7和相应的BeautifulSoup模块(不是bs4)重现这个问题。对我来说很好很漂亮

>>> soup = BeautifulSoup.BeautifulSoup(txt)
>>> print soup
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
</head>
<body>
</body>
</html>
>>soup=beautifulsou.beautifulsou(txt)
>>>印花汤

您遇到的问题是什么,比如您的最终目标是什么,也许somoone可以建议一种解决方法,考虑使用XML解析器:

soup = bs(txt, 'xml')

考虑使用XML解析器:

soup = bs(txt, 'xml')

这是一个错误。我已经承诺将在下一期《美丽的汤》中进行修复

HTMLParser类使用SGML语法规则来处理指令。使用尾随“?”的XHTML处理指令将导致数据中包含“?”


一般来说,正如ThiefMaster所建议的那样,使用“xml”解析器解析XHTML会有更好的结果。

这是一个bug。我已经承诺将在下一期《美丽的汤》中进行修复

HTMLParser类使用SGML语法规则来处理指令。使用尾随“?”的XHTML处理指令将导致数据中包含“?”


总的来说,正如ThiefMaster所建议的那样,使用“xml”解析器解析XHTML会有更好的结果。

只要你不使用相同的软件,说你不能复制它是无用的。我完全同意你从这个角度出发。我只是想建议,如果有选择的话,考虑使用2.7个变量。这一切都是关于美丽的汤4,但谢谢你提到。一旦你不使用相同的软件,说你不能复制它是没有用的。我完全同意你从那个角度来。我只想建议,如果选项是可用的,考虑使用2.7个变量。这一切都是关于美丽的汤4,但谢谢你提到。看看例子中,看起来他们可能有一个问题:“<代码> BeautifulSoup(“”,“XML”)< /代码> ->代码>…/代码>:缺少结束语
。查看中的示例,它们可能有问题:“
美化组(“,“xml”)
->
”:缺少结束语
。谢谢。我将安装lxml解析器或从bzr获得src。谢谢。我将安装lxml解析器或从bzr获取src。