How to scrape data from html which does not belong to any tag
Question: I want to scrape country name and date from the below website html example.
Here the name of the country and date are not inside any tag but just free
data. How to scrape it?

    
    
    <div class="infos">
    <p>
    <span class="hidden-xs hidden-sm">Item offered for sale by:<br/></span>
    <span class="slk" id="product_seller_firstname"  title="#sl#members#sl#profile-1075689#sh#">Sophie</span> (Germany) <br/>
    <span style="font-weight: normal; font-size: 12px;">Individual Seller</span>
    <br/>
    
                                    May 29, 2016 <br/>
    
                                                                        4 items sold </p>
    

I have fetched the data for the class "infos" like this
`getinfo=soup.find_all("div",{"class":"infos"})` How to get the value
**"Germany"** and date **May 29,2016** from it?

Note I have already refered the related questions
[28075119](http://stackoverflow.com/questions/28075119/python-scraping-
beautiful-soup-to-obtain-data-from-this-html) and
[37475110](http://stackoverflow.com/questions/37475110/scrape-information-
from-challenging-website-with-no-guiding-html-structure). But I could not get
the answer from my problem.


Answer: You can try specifically filtering out the elements that are not tags:

    
    
    import bs4
    
    html = """<div class="infos">
    <p>
    <span class="hidden-xs hidden-sm">Item offered for sale by:<br/></span>
    <span class="slk" id="product_seller_firstname"  title="#sl#members#sl#profile-1075689#sh#">Sophie</span> (Germany) <br/>
    <span style="font-weight: normal; font-size: 12px;">Individual Seller</span>
    <br/>
    
                                    May 29, 2016 <br/>
    
                                                                        4 items sold </p>"""
    
    soup = bs4.BeautifulSoup(html, "lxml")
    text_nodes = [c.strip() for c in soup.find('p').children if not isinstance(c, bs4.element.Tag)]
    
    # Remove empty strings (previously just whitespace)
    text_nodes = [c for c in text_nodes if c]
    
    print(text_nodes)
    

Output:

    
    
    [u'(Germany)', u'May 29, 2016', u'4 items sold']
    

But I don't know how robust this is.

