Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.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 BeautifulSoup缺少/跳过标记_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

Python BeautifulSoup缺少/跳过标记

Python BeautifulSoup缺少/跳过标记,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,如果你能给我指出正确的方向,我将不胜感激。是否有更好的方法来实现这一点并捕获所有数据(使用html标记类“Document Text”) 如果我真的喜欢这个。我在原始html字符串的末尾缺少了一些标记,字符串的大小是20K(所以它有很多数据) 下面是用于刮取的代码,该代码目前运行良好,但添加了第二个新标记,但它已损坏 soup = BeautifulSoup(r.content, 'html5lib') c.case_html = str(soup.find('div', class_='D

如果你能给我指出正确的方向,我将不胜感激。是否有更好的方法来实现这一点并捕获所有数据(使用html标记类“Document Text”)

如果我真的喜欢这个。我在原始html字符串的末尾缺少了一些标记,字符串的大小是20K(所以它有很多数据)

下面是用于刮取的代码,该代码目前运行良好,但添加了第二个新标记,但它已损坏

 soup = BeautifulSoup(r.content, 'html5lib')
 c.case_html = str(soup.find('div', class_='DocumentText').find_all(['p','center','small']))
 print(self.case_html)
示例html如下所示,原始大小约为20K字符串

<form name="form1" id="form1">
<div id="theDocument" class="DocumentText" style="position: relative; float: left; overflow: scroll; height: 739px;">
<p>PTag</p>
<p> <center> First center </center> </p>
<small> this is small</small>
<p>...</p>
<p> <center> Second Center </center> </p>
<p>....</p>
</div>
</form>

对苯二甲酸乙二醇酯

第一中心

这个很小

第二中心

预期的产出是这样的

<div id="theDocument" class="DocumentText" style="position: relative; float: left; overflow: scroll; height: 739px;">
<p>PTag</p>
<p> <center> First center </center> </p>
<small> this is small</small>
<p>...</p>
<p> <center> Second Center </center> </p>
<p>....</p>
</div>

对苯二甲酸乙二醇酯

第一中心

这个很小

第二中心


您可以试试这个。我只是根据您给定的html代码来回答。如果你需要澄清,请告诉我。谢谢

 soup = BeautifulSoup(r.content, 'html5lib')
 case_html = soup.select('div.DocumentText')
 print(case_html.get_text())

c.case\u html=str(soup.find('div',class='DocumentText')
为什么要将其转换为
string
?要从上面粘贴的元素中解析什么文本?预期输出是什么?预期输出是
 soup = BeautifulSoup(r.content, 'html5lib')
 case_html = soup.select('div.DocumentText')
 print(case_html.get_text())