Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.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 bs4.element.ResultSet子集问题_Python_Beautifulsoup - Fatal编程技术网

Python bs4.element.ResultSet子集问题

Python bs4.element.ResultSet子集问题,python,beautifulsoup,Python,Beautifulsoup,我用BeautifulSoup从一些网页源代码中抄袭了一个结果集。然后我尝试解析结果集的文本内容。这很好,但是我也返回了文本的标题,这是我不想要的 守则如下: syn_divs = soup.findAll("div", {"class": "synopsis-container"}) for syn in syn_divs: if syn.text != "Synopsis": print syn.text <div class="synopsis-con

我用BeautifulSoup从一些网页源代码中抄袭了一个结果集。然后我尝试解析结果集的文本内容。这很好,但是我也返回了文本的标题,这是我不想要的

守则如下:

syn_divs = soup.findAll("div", {"class": "synopsis-container"})

for syn in syn_divs:

    if syn.text != "Synopsis":

        print syn.text
<div class="synopsis-container">
<h2 class="section-title smaller">Synopsis</h2>
<p class="synopsis" itemprop="description">Two lovers - Muslim Ali (Adam Bakri) and Christian Nino (María Valverde) - have their marriage hopes thwarted by her Georgian parents and then an act carried out by Ali that forces him to flee a mountain village.  After reuniting, the couple are later separated by the Soviet invasion of Azerbaijan when Ali opts to take on the Red Army. Christopher Hampton (Dangerous Liaisons) adapts the 1937 novel.</p>
</div>
Synopsis
Two lovers - Muslim Ali (Adam Bakri) and Christian Nino (María Valverde) - have their marriage hopes thwarted by her Georgian parents and then an act carried out by Ali that forces him to flee a mountain village.  After reuniting, the couple are later separated by the Soviet invasion of Azerbaijan when Ali opts to take on the Red Army. Christopher Hampton (Dangerous Liaisons) adapts the 1937 novel.
结果集内容如下所示:

syn_divs = soup.findAll("div", {"class": "synopsis-container"})

for syn in syn_divs:

    if syn.text != "Synopsis":

        print syn.text
<div class="synopsis-container">
<h2 class="section-title smaller">Synopsis</h2>
<p class="synopsis" itemprop="description">Two lovers - Muslim Ali (Adam Bakri) and Christian Nino (María Valverde) - have their marriage hopes thwarted by her Georgian parents and then an act carried out by Ali that forces him to flee a mountain village.  After reuniting, the couple are later separated by the Soviet invasion of Azerbaijan when Ali opts to take on the Red Army. Christopher Hampton (Dangerous Liaisons) adapts the 1937 novel.</p>
</div>
Synopsis
Two lovers - Muslim Ali (Adam Bakri) and Christian Nino (María Valverde) - have their marriage hopes thwarted by her Georgian parents and then an act carried out by Ali that forces him to flee a mountain village.  After reuniting, the couple are later separated by the Soviet invasion of Azerbaijan when Ali opts to take on the Red Army. Christopher Hampton (Dangerous Liaisons) adapts the 1937 novel.
我想要的是返回电影摘要,但我不想同时返回标题
synopsis
。我需要在代码中修改什么


谢谢

汤。选择('div.synosis-container p')
应该这样做吗?是的,这似乎成功了。谢谢。或者可能<代码>汤。查找所有('p',class='synopsis')也许。。。您可能想自行回答,但我想知道是否有一个dupe在某处显示如何使用
。选择
以选择BS4中的嵌套元素。。。