Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.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 lxml.html找不到正文标记_Python_Beautifulsoup_Lxml - Fatal编程技术网

Python lxml.html找不到正文标记

Python lxml.html找不到正文标记,python,beautifulsoup,lxml,Python,Beautifulsoup,Lxml,我使用lxml.html解析各种html页面。现在我意识到,至少在某些页面上,尽管存在body标记,但它找不到body标记,而BeautifulSoup找到了body标记(即使它使用lxml作为解析器) 示例页:(剩余部分) 任何关于这里发生的事情的猜测都是受欢迎的:) 更新: 问题似乎与编码有关 # working version body = lxml.html.document_fromstring(html_string.encode('unicode-escape')).find('b

我使用lxml.html解析各种html页面。现在我意识到,至少在某些页面上,尽管存在body标记,但它找不到body标记,而BeautifulSoup找到了body标记(即使它使用lxml作为解析器)

示例页:(剩余部分)

任何关于这里发生的事情的猜测都是受欢迎的:)

更新:

问题似乎与编码有关

# working version
body = lxml.html.document_fromstring(html_string.encode('unicode-escape')).find('body')

您可以使用以下内容:

import requests
import lxml.html

html_string = requests.get("https://plus.google.com/").content
body = lxml.html.document_fromstring(html_string).find('body')

body变量包含body html元素

您的
html\u字符串是什么
?@jackfleet它的内容。我没有加,因为它很大,很有趣。您的代码似乎工作正常,但它似乎与我以前所做的相当。区别似乎在于您使用的是编码内容,而我使用的是手动复制的源代码。我会调查的,泰!我看到的主要区别是html标记及其内容是从各种JavaScripts的执行中生成的。body标记必须是硬编码的,否则我们的代码都不能工作,是吗?我仔细查看了源代码,发现了一些十六进制编码字符(例如.\x3d)。看起来它们破坏了lxml,而beautiful soup可以处理它。
import requests
import lxml.html

html_string = requests.get("https://plus.google.com/").content
body = lxml.html.document_fromstring(html_string).find('body')