3

I have the following code:

sauce = urllib.request.urlopen('https://www.iproperty.com.my/sale/selangor/all-commercial/?q=UOA%20Business%20Park').read()
soup = bs.BeautifulSoup(sauce,'html.parser')

price = soup.find_all('ul',class_='listing-primary-price jMWEse')

BUA = soup.find_all('li',class_='attributes-price-per-unit-size-item builtUp-attr fsbnan')


for data in price:
    Price =  data.text
    print(Price)

for data in BUA:
    BUA =  data.text
    print(BUA)

printing Price and BUA gives me the following results:

Price:
RM 1,067,490
RM 2,246,160
RM 929,160
RM 1,321,000
RM 103,840,000

BUA:
Built-up : 1,227 sq. ft.Built-up : 1,227 sq. ft.
Built-up : 2,292 sq. ft.Built-up : 2,292 sq. ft.
Built-up : 1,044 sq. ft.Built-up : 1,044 sq. ft.
Built-up : 1,335 sq. ft.Built-up : 1,335 sq. ft.
Built-up : 118,000 sq. ft.Built-up : 118,000 sq. ft.

My questions is, how can I load Price and BUA into a Pandas Dataframe because I would like to join the both of them and print an end result with something like:

    Price:              BUA:        
0   RM 1,067,490        Built-up : 1,227 sq. ft.Built-up : 1,227 sq. ft.
1   RM 2,246,160        Built-up : 2,292 sq. ft.Built-up : 2,292 sq. ft.
2   RM 929,160          Built-up : 1,044 sq. ft.Built-up : 1,044 sq. ft.
3   RM 1,321,000        Built-up : 1,335 sq. ft.Built-up : 1,335 sq. ft.
4   RM 103,840,000      Built-up : 118,000 sq. ft.Built-up : 118,000 sq. ft.

Another reason why I want to put them into a Pandas Dataframe is because I need to do some calculations in Excel later on.

2 Answers 2

2

I believe you need:

a = [data.text for data in price]
b = [data.text for data in BUA]

df = pd.DataFrame({'price':a, 'BUA':b}, columns=['price','BUA'])
Sign up to request clarification or add additional context in comments.

1 Comment

Working very well!! Thank you!
0
  df = pd.DataFrame()
  df['price'] = [data.text for data in price]
  df['bua'] = [data.text for data in bua]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.