in Education by
I have the below (simplified) code, which uses the following source:

line 1

soup = BeautifulSoup('

line 1

') ele = soup.find('p').nextSibling somehow_print_tag_of_ele_here I want to get the tag of ele, in this case "div". However, I only seem to be able to get the tag of its children. Am I missing something simple? I thought that I could do ele.tag.name, but that is an exception since tag is None. #Below correctly prints the div element " " print ele #Below prints "None". Printing tag.name is an exception since tag is None print ele.tag #Below prints "a", the child of ele allTags = ele.findAll(True) for e in allTags: print e.name At this point, I am considering doing something along the way of getting the parent of ele, then getting the tags of parent's children and, having counted how many upper siblings ele has, counting down to the correct child tag. That seems ridiculous. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
ele is already a tag, try doing this: soup = BeautifulSoup('

line 1

') print(soup.find('p').nextSibling.name) so in your example it would be just print(ele.name)

Related questions

0 votes
    The sample xml file is shown below What should I write in XSLT so that i can get the sample ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Penny has 5 children, 1st is January, 2nd kid February, 3rd is called march , 4th is April. What is the name of the 5th....
asked Feb 11, 2021 in Education by JackTerrance
0 votes
    What is not true in context of HTML tag ? O Table cell changes its width automatically based on content O We can ... table border is o Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    Which is not a correct name for an XML element? a) b) c) d) Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    I am starting to work with python again after 8 years. I am trying to do the program with BeautifulSoup and an ... '__main__': main() Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    I have an XML with Text elements that can include tagged text and depending on the elements attribute value ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    An element is composed of: a. ON tag and OFF tag b. The content between the opening and closing tag c. Both a and b Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
0 votes
    The ________ function returns its argument with a modified shape, whereas the ________ method modifies the array ... answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    The ________ function returns its argument with a modified shape, whereas the ________ method modifies the array itself. (a) ... (c) reshape2, resize (d) all of the mentioned...
asked Oct 7, 2021 in Technology by JackTerrance
0 votes
    I'm not a coder. I have a Powershell script .ps1 that goes into all subfolders of "db" and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    The face attributes of tag is used to specify the name of the font. True or false no spam messages plzz… Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    Can we use just the tag name of structures to declare the variables for the same?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    I am trying to do some validation on the file name before it's saved. Here are my three file- ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    Question I am trying to run a single Kafka instance in docker. I can create topics but cannot consume ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Why coal or petrol does not burn by itself in air but once initiated by flame, it continues to burn? Select the correct answer from above options...
asked Jan 4, 2022 in Education by JackTerrance
...