Does Beautiful Soup allow for the exclusion of html code by div (or other filters)?

Viewed 1962

Does Beautiful Soup allow for the exclusion of html code by div (or other filters)?

I am trying to parse code that is very poorly written, where there is not an appropriate tag, id, class or anything else to key on parsing the desired content.

What I am looking for is a select or findall everything in a id that is not a certain class. Per the sample code below, I want everything in id-main that is not contained in class-toc-indentation.

Below I have main_txt and toc_txt, though my goal is to have main_txt with toc_txt further parsed out.

    soup = BeautifulSoup(orig_file)
    title = soup.find('title')    
    main_txt = soup.findAll(id='main')[0]
    toc_txt = soup.findAll(class_ ='toc-indentation')

I did my best to find the answer but just can seem to locate anything that will help me.

Please let me know if you have any questions or required further info.

Any assistance will be highly appreciated.

2 Answers
Related