Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print multiple at once
#1
hi guys,

is it possible to print multiple things/rows at once instead of print1, print2 etc?

On example presented below i would like to print all in section 'for..'

from bs4 import BeautifulSoup
import requests
import pandas as pd
import re
import urllib

headers = {
    'Sec-Fetch-Mode': 'cors',
    'Referer': 'https://www.pararius.com/apartments/amsterdam',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36',
    'Content-Type': 'text/plain',
}

data = '{"tags":[{"sizes":[{"width":728,"height":90},{"width":970,"height":250}],"primary_size":{"width":728,"height":90},"ad_types":["banner"],"uuid":"5f5a2718d3aa6d","id":11247563,"allow_smaller_sizes":false,"use_pmt_rule":false,"prebid":true,"disable_psa":true},{"sizes":[{"width":728,"height":90},{"width":970,"height":250}],"primary_size":{"width":728,"height":90},"ad_types":["banner"],"uuid":"66526a063a1a8c","id":11247564,"allow_smaller_sizes":false,"use_pmt_rule":false,"prebid":true,"disable_psa":true}],"sdk":{"source":"pbjs","version":"2.19.0-pre"},"gdpr_consent":{"consent_string":"BOmDsv2OmDsv2BQABBENCN-AAAAmd7_______9______5uz_Ov_v_f__33e8__9v_l_7_-___u_-3zd4-_1vf99yfm1-7etr3tp_87ues2_Xur__59__3z3_9phPrsk89ryw","consent_required":true},"referrer_detection":{"rd_ref":"https%3A%2F%2Fwww.pararius.com%2Fapartments%2Famsterdam","rd_top":true,"rd_ifs":1,"rd_stk":"https%3A%2F%2Fwww.pararius.com%2Fapartments%2Famsterdam,https%3A%2F%2Fwww.pararius.com%2Fapartments%2Famsterdam"}}'

r = requests.get('https://www.pararius.com/apartments/amsterdam', headers=headers, data=data)
content = (r.text)
soup = BeautifulSoup(content, 'html.parser')


for section in soup.find_all(class_='property-list-item-container'):
    dlink = section.find('a').get('href')
    type = section.find('span', {'class': 'type'}).text
    neighborhood = section.find('a').text.strip().split()[1]
    size = section.find('li', {'class': 'surface'}).text.strip().split()[0]
    bedrooms = section.find('li', {'class': 'surface'}).text.strip().split()[2]
    furniture = section.find('li', {'class': 'surface'}).text.strip().split()[4]
    availablefrom = size = section.find('li', {'class': 'surface'}).text.strip().split()[6]
    #print(availablefrom)
    break
Reply
#2
if using python 3.6 or newer, you can use f-string
example:
    print(f"dlink: {dlink}\ntype: {type}\nneighborhood: {neighborhood}"
put as much as you want in the string.
Reply
#3
(Aug-30-2019, 11:20 AM)Larz60+ Wrote: if using python 3.6 or newer, you can use f-string
example:
    print(f"dlink: {dlink}\ntype: {type}\nneighborhood: {neighborhood}"
put as much as you want in the string.

thank you :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question How to print multiple elements from multiple lists in a FOR loop? Gilush 6 2,930 Dec-02-2020, 07:50 AM
Last Post: Gilush
  How to print string multiple times on new line ace19887 7 5,730 Sep-30-2020, 02:53 PM
Last Post: buran
  print function help percentage and slash (multiple variables) leodavinci1990 3 2,475 Aug-10-2020, 02:51 AM
Last Post: bowlofred
  How to print out multiple drinks instead of just one based on the input? jayfre 4 4,188 Jul-01-2020, 06:53 PM
Last Post: menator01
  How to print string multiple times separated by delimiter Mekala 1 1,892 May-23-2020, 09:21 AM
Last Post: Yoriz
  print python json dump onto multiple lines lhailey 2 19,824 Mar-02-2020, 12:47 PM
Last Post: vishalhule
  How to execute a string with multiple sqlite statements and print results? shanepy 0 2,260 Nov-20-2018, 10:19 PM
Last Post: shanepy
  Print multiple record lines ntigner 3 3,416 Feb-08-2018, 05:34 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020