how to get partial text from a long tag using BeautifulSoup
<p>I have been studying a shopping website, and I want to extract the brandname and the product name from its html code like the following:</p>

<p><code>&lt;h1 class="product-name elim-suites"&gt;Chantecaille&lt;span itemprop="name" &gt;Limited Edition Protect the Lion Eye Palette&lt;/span&gt;&lt;/h1&gt;</code></p>

<p>I tried: <code>results = soup.findAll("h1", {"class" : "product-name elim-suites"})[0].text</code></p>

<p>and got: <code>u'ChantecailleLimited Edition Protect the Lion Eye Palette'</code></p>

<p>As you can see, Chantecaille is the brandname, the rest is the product name, but they are now sticked to each other, any suggestion? Thank you!</p>

<p>You can use <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#next-sibling-and-previous-sibling" rel="nofollow"><code>previous_sibling</code></a>, which gets the previous node that has the same parent (same level in the parse tree).</p>

<p>Also, instead of <code>findAll</code>, when you are searching for a single element, use <code>find</code>.</p>

<pre><code>item_span = soup.find("h1", {"class" : "product-name elim-suites"}).find("span")

product_name = item_span.previous_sibling
brand_name = item_span.text

print product_name
print brand_name
</code></pre>

<p>Output:</p>

<pre><code>Chantecaille
Limited Edition Protect the Lion Eye Palette
</code></pre>

python parsing beautifulsoup