Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/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 Beauty soup和请求包时HTML内容不正确_Python_Beautifulsoup - Fatal编程技术网

使用python Beauty soup和请求包时HTML内容不正确

使用python Beauty soup和请求包时HTML内容不正确,python,beautifulsoup,Python,Beautifulsoup,我在使用JSoup和BeautifulSoup解析网页后得到的HTML内容与下面所示的不同。有没有人有同样的问题,你能告诉我是怎么解决的吗 检查每个块中的第三行- =======JSoup <div class="col-full"> <p><strong>Index Notifications</strong></p> <p></p><br> <p> <br /> <

我在使用JSoup和BeautifulSoup解析网页后得到的HTML内容与下面所示的不同。有没有人有同样的问题,你能告诉我是怎么解决的吗

检查每个块中的第三行-

=======JSoup

<div class="col-full">
 <p><strong>Index Notifications</strong></p>
 <p></p><br>
<p> <br /> <b> March 28, 2014</b>
<br >
<br >

索引通知



2014年3月28日

=========美丽的乌苏

<div class="col-full">
<p><strong>Index Notifications</strong></p>
<p><p> <br>
<b> March 28, 2014</b>
<br>
<br>

索引通知


2014年3月28日


解析损坏的HTML时,不同的解析器会尝试以不同的方式修复损坏的标记;对于如何处理此类错误,没有硬性规定

BeautifulSoup可以,而且每一个都会以不同的方式处理您的内容:

>>> import requests
>>> from bs4 import BeautifulSoup
>>> url = 'http://www.wisdomtree.com/etfs/index-notices.aspx'
>>> html = requests.get(url).content
>>> BeautifulSoup(html, 'html.parser').find('div', class_='col-full')
<div class="col-full">
<p><strong>Index Notifications</strong></p>
<p><p> <br>
<b> March 28, 2014</b>
<br> <br>
# ... cut ...
>>> BeautifulSoup(html, 'lxml').find('div', class_='col-full')
<div class="col-full">
<p><strong>Index Notifications</strong></p>
<p></p><p> <br/>
<b> March 28, 2014</b>
<br/> <br/>
# ... cut ...
>>> BeautifulSoup(html, 'html5lib').find('div', class_='col-full')
<div class="col-full">

            <p><strong>Index Notifications</strong></p>
            <p></p><p> <br/>
<b> March 28, 2014</b>
<br/>  <br/>
# ... cut ...
导入请求 >>>从bs4导入BeautifulSoup >>>url='1〕http://www.wisdomtree.com/etfs/index-notices.aspx' >>>html=requests.get(url.content) >>>美化组(html,'html.parser')。查找('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。 >>>beautifulsou(html,'lxml')。find('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。 >>>beautifulsou(html,'html5lib')。find('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。
html5lib
解析器是最慢的,但通常会像大多数浏览器一样解析损坏的HTML。
lxml
html5lib
都像JSoup一样解析了文档的这一特定部分。

解析损坏的HTML时,不同的解析器会尝试以不同的方式修复损坏的标记;对于如何处理此类错误,没有硬性规定

BeautifulSoup可以,而且每一个都会以不同的方式处理您的内容:

>>> import requests
>>> from bs4 import BeautifulSoup
>>> url = 'http://www.wisdomtree.com/etfs/index-notices.aspx'
>>> html = requests.get(url).content
>>> BeautifulSoup(html, 'html.parser').find('div', class_='col-full')
<div class="col-full">
<p><strong>Index Notifications</strong></p>
<p><p> <br>
<b> March 28, 2014</b>
<br> <br>
# ... cut ...
>>> BeautifulSoup(html, 'lxml').find('div', class_='col-full')
<div class="col-full">
<p><strong>Index Notifications</strong></p>
<p></p><p> <br/>
<b> March 28, 2014</b>
<br/> <br/>
# ... cut ...
>>> BeautifulSoup(html, 'html5lib').find('div', class_='col-full')
<div class="col-full">

            <p><strong>Index Notifications</strong></p>
            <p></p><p> <br/>
<b> March 28, 2014</b>
<br/>  <br/>
# ... cut ...
导入请求 >>>从bs4导入BeautifulSoup >>>url='1〕http://www.wisdomtree.com/etfs/index-notices.aspx' >>>html=requests.get(url.content) >>>美化组(html,'html.parser')。查找('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。 >>>beautifulsou(html,'lxml')。find('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。 >>>beautifulsou(html,'html5lib')。find('div',class='col-full') 索引通知


2014年3月28日

# ... 切。。。
html5lib
解析器是最慢的,但通常会像大多数浏览器一样解析损坏的HTML。
lxml
html5lib
都像JSoup一样解析了文档的这个特定部分。

如果您破坏了HTML输入,解析器必须充分利用它。不同的解析器做的不同。非常感谢。我将尝试使用lxml解析器。你怎么知道我在做《智慧树》?:-)纯粹的运气;谷歌搜索代码片段中的两个特定短语(使用引号)只得到一次点击。如果你破坏了HTML输入,解析器必须充分利用它。不同的解析器做的不同。非常感谢。我将尝试使用lxml解析器。你怎么知道我在做《智慧树》?:-)纯粹的运气;谷歌搜索代码片段中的两个特定短语(使用引号)只得到一个结果。