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 7496245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:32:37+00:00 2026-05-29T18:32:37+00:00

I have written a pretty simple code to get the first result for any

  • 0

I have written a pretty simple code to get the first result for any term on urbandictionary.com. I started by writing a simple thing to see how their code is formatted.

def parseudtest(searchurl):    
    url = 'http://www.urbandictionary.com/define.php?term=%s' %searchurl
    url_info = urllib.urlopen(url)
    for lines in url_info:
        print lines

For a test, I searched for ‘cats’, and used that as the variable searchurl. The output I receive is of course a gigantic page, but here is the part I care about:

<meta content='He set us up the bomb. Also took all our base.' name='Description' />

<meta content='He set us up the bomb. Also took all our base.' property='og:description' />

<meta content='cats' property='og:title' />

<meta content="http://static3.urbandictionary.com/rel-1e0b481/images/og_image.png" property="og:image" />

<meta content='Urban Dictionary' property='og:site_name' />

As you can see, the first time the element “meta content” appears on the site, it is the first definition for the search term. So I wrote this code to retrieve it:

def parseud(searchurl):    
    url = 'http://www.urbandictionary.com/define.php?term=%s' %searchurl
    url_info = urllib.urlopen(url)
    if (url_info):
        xmldoc = minidom.parse(url_info)
    if (xmldoc):
        definition = xmldoc.getElementsByTagName('meta content')[0].firstChild.data
        print definition

For some reason the parsing doesn’t seem to be working and invariably encounters an error every time. It is especially confusing since the site appears to use basically the same format as other sites I have successfully retrieved specific data from. If anyone could help me figure out what I am messing up here, it would be greatly appreciated.

  • 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-29T18:32:38+00:00Added an answer on May 29, 2026 at 6:32 pm

    As you don’t give the traceback for the errors that occur it’s hard to be specific, but I assume that although the site claims to be XHTML it’s not actually valid XML. You’d be better off using Beautiful Soup as it is designed for parsing HTML and will correctly handle broken markup.

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

Sidebar

Related Questions

I have written a pretty simple Windows service in C# that starts up automatically
I have written something like this pretty easily in C# ( string GetUrl(new {
I have written what I thought to be a pretty solid Linq statement but
I've written an entire app pretty successfully in Django but I have this nagging
I have written some code in my VB.NET application to send an HTML e-mail
I have written a site in Prototype but want to switch to jQuery. Any
Just started exploring Cocoa so pretty much a total noob. I've written a very
I have written a simple server - client program with Swing interface using singleton
I have a Windows Workflow application that uses classes I've written for COM automation.
I have a simple console app written in C#. I want to be able

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.