How to check if elements of the BeautifulSoup parse tree are in the same <p> tag?
How to check if elements of the BeautifulSoup parse tree are in the same
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you know both nodes are directly underneath a
<p>tag, check equality of the nodesnodea.getParent() == nodeb.getParent(); more generally, search (recursively) upwards until you hit a<p>tag. Do this separately for each node, then compare the results for equality:(Let’s ignore the corner-case of nested
<p>tags.)else, iterate through all
<p>tags, using text search or regex(es) to search for matches on both: