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

  • SEARCH
  • Home
  • 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 8937051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:20:42+00:00 2026-06-15T10:20:42+00:00

I’m aware that there are modules that fully simplify this function, but saying that

  • 0

I’m aware that there are modules that fully simplify this function, but saying that I am running from a base install of python (standard modules only), how would I extract the following:

I have a list. This list is the contents, line by line, of a webpage. Here is a mock up list (unformatted) for informative purposes:

<script>
    link = "/scripts/playlists/1/" + a.id + "/0-5417069212.asx";
<script>

"<a href="/apps/audio/?feedId=11065"><span class="px13">Eastern Metro Area Fire</span>"

From the above string, I need the following extracted. The feedId (11065), which is incidentally a.id in the code above., “/scripts/playlists/1/” and “/0-5417069212.asx”. Remembering that each of these lines is just contents from objects in a list, how would I go about extracting that data?

Here is the full list:

contents = urllib2.urlopen("http://www.radioreference.com/apps/audio/?ctid=5586")

Pseudo:

from urllib2 import urlopen as getpage
page_contents = getpage("http://www.radioreference.com/apps/audio/?ctid=5586")

feedID        = % in (page_contents.search() for "/apps/audio/?feedId=%")
titleID       = % in (page_contents.search() for "<span class="px13">%</span>")
playlistID    = % in (page_contents.search() for "link = "%" + a.id + "*.asx";")
asxID         = * in (page_contents.search() for "link = "*" + a.id + "%.asx";")

streamURL     = "http://www.radioreference.com/" + playlistID + feedID + asxID + ".asx"

I plan to format it as such that streamURL should = :

http://www.radioreference.com/scripts/playlists/1/11065/0-5417067072.asx
  • 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-06-15T10:20:43+00:00Added an answer on June 15, 2026 at 10:20 am

    I’d do this with regular expressions. Python’s re module is great!

    However, it’s easier (and faster) to search a single string holding all the page’s text (rather than doing repeated searches line by line). If you can, do a read() on the file-like object you get when you open the URL, rather than readlines() (or directly iterating over the file object). If you can’t do that, you can use "\n".join(list_of_strings) to get the lines back into a single string.

    Here’s some code that works for me on your example URL:

    from urllib2 import urlopen
    import re
    
    contents = urlopen("http://www.radioreference.com/apps/audio/?ctid=5586").read()
    
    playlist_pattern = r'link = "([^"]+)" \+ a.id \+ "([^"]+\.asx)'
    feed_pattern = r'href="/apps/audio/\?feedId=(\d+)"><span class="px13">([^<]+)'
    pattern = playlist_pattern + ".*" + feed_pattern
    
    playlist, asx, feed, title = re.search(pattern, contents, re.DOTALL).groups()
    
    streamURL = "http://www.radioreference.com" + playlist + feed + asx
    
    print title
    print streamURL
    

    Output:

    Eastern Metro Area Fire
    http://www.radioreference.com/scripts/playlists/1/11065/0-5417090148.asx
    

    It’s not strictly necessary to do all the matching in one pass. You can use playlist_pattern and feed_pattern to get two parts each, if you want. It is a little more difficult to split either of the halves up though, since you’ll start running into extra matches for some of the pieces (there are several identical link = "stuff" sections, for instance).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
This could be a duplicate question, but I have no idea what search terms
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.