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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:25:47+00:00 2026-06-09T18:25:47+00:00

I was using Python and regular expressions to find things an HTML document and

  • 0

I was using Python and regular expressions to find things an HTML document and unlike what most people say, it was working perfectly, even though things could go wrong. Anyway, I decided Beautiful Soup would be faster and easier but I don’t really know how to make it do what I did with regex, which was fairly easy, but messy.

I am using this page’s HTML:

http://www.locationary.com/places/duplicates.jsp?inPID=1000000001

EDIT:

Here is the HTML for the main place:

<tr>
<td class="Large Bold" nowrap="nowrap">Riverside Tower Hotel&nbsp;</td>
<td class="Large Bold" width="100%">80 Riverside Drive, New York, New York, United States</td>
<td class="Large Bold" nowrap="nowrap" width="55">&nbsp;<input name="selectCheckBox" type="checkbox" checked="checked" disabled="disabled" />Yes
</td>
</tr>

Example of the first similar place:

<td class="" nowrap="nowrap"><a href="http://www.locationary.com/place/en/US/New_York/New_York/54_Riverside_Dr_Owners_Corp-p1009633680.jsp" target="_blank">54 Riverside Dr Owners Corp</a></td>
<td width="100%">&nbsp;54 Riverside Dr, New York, New York, United States</td>
<td nowrap="nowrap" width="55">

When my program gets it and I use Beautiful Soup to make it more readable, the HTML comes out a little different than Firefox’s “view source”…I don’t know why.

These were my regular expressions:

PlaceName = re.findall(r'"nowrap">(.*)&nbsp;</td>', main)

PlaceAddress = re.findall(r'width="100%">(.*)</td>\n<td class="Large Bold"', main)

cNames = re.findall(r'target="_blank">(.*)</a></td>\n<td width="100%">&nbsp;', main)

cAddresses = re.findall(r'<td width="100%">&nbsp;(.*)</td>\n<td nowrap="nowrap" width="55">', main)

cURLs = re.findall(r'<td class="" nowrap="nowrap"><a href="(.*)" target="_blank">', main)

The first two are for the main place and address. The rest are for the information of the rest of the places. After I made these, I decided I only wanted the first 5 results for cNames, cAddresses, and cURLs, because I don’t need 91 or whatever it was.

I don’t know how to find this kind of information with BS. All I can do with BS is find specific tags and do things with them. This HTML is kind of complicated because all of the info. I want is in tables and the table tags are kind of a mess too…

How do you get that info, and limit it only to the first 5 results or so?

Thanks.

  • 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-09T18:25:49+00:00Added an answer on June 9, 2026 at 6:25 pm

    People say that you can’t parse HTML with regular expressions for a reason, but here’s a simple reason that applies to your regexp: you’ve got \n and &nbsp; in your regexp and those can and will change at random on the page(s) you are trying to parse. When that happens your regexp won’t match and your code will stop working.

    However the task that you are looking to do is really simple

    from BeautifulSoup import BeautifulSoup
    soup = BeautifulSoup(open('this-stackoverflow-page.html'))
    
    for anchor in soup('a'):
        print anchor.contents, anchor.get('href')
    

    yields all the Anchor tags no matter where they appear in the deeply nested structure of this page. Here are lines I excerpted from the output of that three line script:

    [u'Stack Exchange'] http://stackexchange.com
    [u'msw'] /users/282912/msw
    [u'faq'] /faq
    [u'Stack Overflow'] /
    [u'Questions'] /questions
    [u'How to use Beautiful Soup to get plaintext and URLs from an HTML document?'] /questions/11902974/how-to-use-beautiful-soup-to-get-plaintext-and-urls-from-an-html-document
    [u'http://www.locationary.com/places/duplicates.jsp?inPID=1000000001'] http://www.locationary.com/places/duplicates.jsp?inPID=1000000001
    [u'python'] /questions/tagged/python
    [u'beautifulsoup'] /questions/tagged/beautifulsoup
    [u'Marcus Johnson'] /users/1587751/marcus-johnson
    

    It is hard to imagine less code that could do that much work for you.

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

Sidebar

Related Questions

I'm trying to make a simple Python-based HTML parser using regular expressions. My problem
How to parse the string {'result':(Boolean, MessageString)} using Python regular expressions to get Boolean
I'm using regular expressions with a python framework to pad a specific number in
I need to add markup to some text using JavaScript regular expressions. In Python
How to get a value of nested <b> HTML tag in Python using regular
I'm using Python and I want to use regular expressions to check if something
I am using the python prompt to practice some regular expressions. I was wondering
Using Python regular expressions how can you get a True / False returned? All
I'm trying to change wikitext into normal text using Python regular expressions substitution. There
i am using python with re module for regular expressions i want to remove

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.