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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:05:02+00:00 2026-05-26T14:05:02+00:00

This was covered in this post: Python web scraping involving HTML tags with attributes

  • 0

This was covered in this post: Python web scraping involving HTML tags with attributes

But I haven’t been able to do something similar for this web page: http://www.expatistan.com/cost-of-living/comparison/melbourne/auckland?

I’m trying to scrape the values of:

  <td class="price city-2">
                                                      NZ$15.62
                                      <span style="white-space:nowrap;">(AU$12.10)</span>
                                                  </td>
  <td class="price city-1">
                                                      AU$15.82
                              </td>

Basically price city-2 and price city-1 (NZ$15.62 and AU$15.82)

Currently have:

import urllib2

from BeautifulSoup import BeautifulSoup

url = "http://www.expatistan.com/cost-of-living/comparison/melbourne/auckland?"
page = urllib2.urlopen(url)

soup = BeautifulSoup(page)

price2 = soup.findAll('td', attrs = {'class':'price city-2'})
price1 = soup.findAll('td', attrs = {'class':'price city-1'})

for price in price2:
    print price

for price in price1:
    print price

Ideally, I’d also like to have comma separated values for:

<th colspan="3" class="clickable">Food</th>, 

Extracting ‘Food’,

<td class="item-name">Daily menu in the business district</td>

Extracting ‘Daily menu in the business district’

and then the values for price city-2, and price-city1

So the printout would be:

Food, Daily menu in the business district, NZ$15.62, AU$15.82

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-05-26T14:05:03+00:00Added an answer on May 26, 2026 at 2:05 pm

    I find BeautifulSoup awkward to use. Here is a version based on the webscraping module:

    from webscraping import common, download, xpath
    
    # download html
    D = download.Download()
    html = D.get('http://www.expatistan.com/cost-of-living/comparison/melbourne/auckland')
    
    # extract data
    items = xpath.search(html, '//td[@class="item-name"]')
    city1_prices = xpath.search(html, '//td[@class="price city-1"]')
    city2_prices = xpath.search(html, '//td[@class="price city-2"]')
    
    # display and format
    for item, city1_price, city2_price in zip(items, city1_prices, city2_prices):
        print item.strip(), city1_price.strip(), common.remove_tags(city2_price, False).strip()
    

    Output:

    Daily menu in the business district AU$15.82 NZ$15.62

    Combo meal in fast food restaurant (Big Mac Meal or similar) AU$7.40 NZ$8.16

    1/2 Kg (1 lb.) of chicken breast AU$6.07 NZ$10.25

    …

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

Sidebar

Related Questions

This may be something covered in C# 101 but I haven't been able to
I apologize because I know this has been covered over and over again, but
Ok guys, So I know this has been covered before, but what my question
I'm sure this is covered in the documentation somewhere but I have been unable
I know this has been covered before but I cannot find an answer to
I know this has been covered over and over but I just can't understand
I apologize if this question has already been covered on this site, but I
I thought this was covered elsewhere but I don't see it now. Anyway, having
I'm sure this must have been covered before because I'm sure I'm not the
Sorry, I know that this topic has been covered a bit. I've read the

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.