Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 280013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:04:53+00:00 2026-05-12T05:04:53+00:00

How to find out the content between two words or two sets of random

  • 0

How to find out the content between two words or two sets of random characters?

The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can’t remove the JavaScript.

consider this:

<html>
<body>
<div>StartYYYY "Extract HTML", ENDYYYY

</body>

Some Java Scripts code STARTXXXX "Extract JS Code" ENDXXXX.

</html>

So as you see the html markup may not be complete. I can fetch the page, and then without worrying about anything, I want to find the content called “Extract the name” and “Extract the data here in a JavaScript”.

What I am looking for is in python:

Like this:

data = FindBetweenText(UniqueTextBeforeContent, UniqueTextAfterContent, page)

Where page is downloaded and data would have the text I am looking for. I rather stay away from regEx as some of the cases can be too complex for RegEx.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:04:53+00:00Added an answer on May 12, 2026 at 5:04 am

    Here’s my attempt, this is tested. While recursive, there should be no unnecessary string duplication, although a generator might be more optimal

    def bracketed_find(s, start, end, startat=0):
        startloc=s.find(start, startat)
        if startloc==-1:
            return []
        endloc=s.find(end, startloc+len(start))
        if endloc == -1:
            return [s[startloc+len(start):]]
        return [s[startloc+len(start):endloc]] + bracketed_find(s, start, end, endloc+len(end))
    

    and here is a generator version

    def bracketed_find(s, start, end, startat=0):
        startloc=s.find(start, startat)
        if startloc==-1:
            return
        endloc=s.find(end, startloc+len(start))
        if endloc == -1:
            yield s[startloc+len(start):]
            return
        else:
            yield s[startloc+len(start):endloc]
    
        for found in bracketed_find(s, start, end, endloc+len(end)):
            yield found
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Where could I find out the content type for a specific file format/extension? For
I find out how to replace the busy cursor here: http://livedocs.adobe.com/flex/3/html/cursormgr_3.html However, how do
at this page new customer , there is some clash between the two scripts.
The object is to find sets such as <!-- content:start -->some content here<!-- content:stop
How can I find out which node in a tree list the context menu
Can we write a c program to find out time spent in context switch
I need to find out how to format numbers as strings. My code is
How can I find out which Service Pack is installed on my copy of
I would like to find out safe ways of implementing three dimensional arrays of
I'm trying to find out how much memory my own .Net server process is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.