0

need to get sentence between tags with Selenium and Python :

       <h2 id='PO-PF2' class="section">Program Information</h2>
        Length: Two-year Ontario College Graduate Certificate program
        <br />Delivery Sequence:<br />

Using find_element_by_xpath in different variations didn't return any results.

Using driver.find_element_by_tag_name("body").text and then parse it for required sentence works but is there any other way ?

Expected result : Length: Two-year Ontario College Graduate Certificate program

UPD:

'(?<=Length:)([\s\S]*?)(?=\n)' 

Covered all needed cases

2
  • 1
    Could you please specify what result you are expecting? Commented Dec 21, 2018 at 20:15
  • @KshetraMohanPrusty, Thank you, after your question I got the answer ! Commented Dec 21, 2018 at 20:19

1 Answer 1

1

You can use the regex here: (?=Length)(.*)(?<=program)

(?=...) Asserts that the given subpattern can be matched here, without consuming characters

(?<=...) Ensures that the given pattern will match, ending at the current position in the expression. The pattern must have a fixed width. Does not consume any character

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, just solved the same way like minute ago. Will mark as correct.
You should clarify that these are positive look-aheads and positive look-behinds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.