Text Information not scrape properly-Python
<p>I need to scrape the text information between the following HTML. My code below is not working properly for cases where tag and class names are same. Here i need to get the text in single list element and not as two different list element. The code i have written here for the case where there is no split like below. In my case i need to scrape both kind of text and append it to a single list.</p>

<p><strong>Sample HTML code(where list element is one)- working correctly:</strong></p>

<pre><code>&lt;DIV CLASS="c5"&gt;&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;The board of Hillshire Brands has withdrawn its recommendation to acquire frozen foods maker Pinnacle Foods, clearing the way for Tyson Foods' $8.55bn takeover bid.&lt;/SPAN&gt;&lt;SPAN CLASS="c2"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;Last Monday Tyson won the bidding war for Hillshire, maker of Ball Park hot dogs, with a $63-a-share offer, topping rival poultry processor Pilgrim's Pride's $7.7bn bid.&lt;/SPAN&gt;&lt;/P&gt;
</code></pre>

<p><strong>Sample HTML Code(where list element is two):</strong></p>

<pre><code>&lt;DIV CLASS="c5"&gt;&lt;BR&gt;&lt;P CLASS="c6"&gt;&lt;SPAN CLASS="c8"&gt;HIGHLIGHT:&lt;/SPAN&gt;&lt;SPAN CLASS="c2"&gt;&amp;nbsp;News analysis&lt;BR&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;M&amp;amp;A simmers as producers swallow up brands to win shelf space, writes Neil Munhsi&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;BR&gt;&lt;DIV CLASS="c5"&gt;&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;Pickles may go with sandwiches, as Hillshire Brands chief executive Sean Connolly put it two weeks ago.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;But many were puzzled by the US food group's announcement that it would pay $6.6bn to acquire New Jersey-based rival Pinnacle Foods, maker of Vlasic pickles and Birds Eye frozen food.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P CLASS="c9"&gt;&lt;SPAN CLASS="c2"&gt;Without the sort of mooted cost savings necessary to justify the purchase price, many saw the move by Hillshire, known in the US for Ball Park hot dogs and Jimmy Dean sausages, as a way to head off a potential takeover.&lt;/SPAN&gt;&lt;SPAN CLASS="c2"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
</code></pre>

<p><strong>Python Code:</strong></p>

<pre><code>soup = BeautifulSoup(response, 'html.parser')
tree = html.fromstring(response)
values = [[''.join(text for text in div.xpath('.//p[@class="c9"]//span[@class="c2"]//text()'))] for div in tree.xpath('//div[@class="c5"]') if div.getchildren()]
        split_at = ','
textvalues = [list(g) for k, g in groupby(values, lambda x: x != split_at) if k]
list2 = [x for x in textvalues[0] if x]
def purify(list2):
     for (i, sl) in enumerate(list2):
          if type(sl) == list:
              list2[i] = purify(sl)
            return [i for i in list2 if i != [] and i != '']
list3=purify(list2)
flattened = [val for sublist in list3 for val in sublist]
</code></pre>

<p><strong>Current Output:</strong></p>

<pre><code>["M&amp;A simmers as producers swallow up brands to win shelf space, writes Neil Munhsi","--Remaining text--"]
</code></pre>

<p><strong>Expected Sample Output:</strong></p>

<pre><code>["M&amp;A simmers as producers swallow up brands to win shelf space, writes Neil Munhsi --Remaining text--"]
</code></pre>

<p>Please help me to resolve the above issue.</p>