Bir Satırda Cümleyi İstediğim noktada Başlatma

Merhabalar,başlıkta yeterince anlatabildim mi bilmiyorum ama örnekle açıklamaya çalışayım.
Mesela bir siteden veri çekiyorum. imbd filmleri olsun.

  1.  Terminator 2: Judgment Day(1991)               Filmin Ratingi 8.5
    
  2.  Back to the Future(1985)               Filmin Ratingi 8.5
    
  3.  Modern Times(1936)             Filmin Ratingi 8.5
    

Elime şöyle bir çıktı geliyor. Filmlerin puanları yazan kısımda filmlerin uzunluklarına göre boşluk atıyor. Ben bunu aşağıdaki duruma getirmek istiyorum.

  1.  Terminator 2: Judgment Day(1991)                       Filmin Ratingi 8.5
    
  2.  Back to the Future(1985)                               Filmin Ratingi 8.5
    
  3.  Modern Times(1936)                                     Filmin Ratingi 8.5
    

Fikir vermesi açısından kod aşağıda:

import requests 
from bs4 import BeautifulSoup

url = "https://www.imdb.com/chart/top"


site_cekimi = requests.get(url)

html_iceriği = site_cekimi.content

soup = BeautifulSoup(html_iceriği,"html.parser")


basliklar = soup.find_all("td",{"class":"titleColumn"})

puan = soup.find_all("td",{"class":"ratingColumn imdbRating"})



for isim,puan in zip(basliklar,puan):
    print(isim.text.strip().replace("\n",""),"\t\tFilmin Ratingi",puan.text.strip().replace("\n","   ")) 

Şimdiden teşekkürler.

Merhabalar,

IMDB’den cektigin datayi (basliklar, puan) python koduna cevirip yazabilir misin?

basliklar = [("Terminator 2: Judgment Day", 1991), ...]
puan = [8.5, ...]

gibi. bs4 kurmakla, sorgu yapip cevabini filtrelemekle ugrasmak istemiyorum.

Merhaba, aşağıdaki şekilde ihtiyacınızı görür umarım.

Başlıklar :
[‘1.The Shawshank Redemption(1994)’, ‘2.The Godfather(1972)’, ‘3.The Godfather: Part II(1974)’, ‘4.The Dark Knight(2008)’, ‘5.12 Angry Men(1957)’, “6.Schindler’s List(1993)”, ‘7.The Lord of the Rings: The Return of the King(2003)’, ‘8.Pulp Fiction(1994)’, ‘9.Il buono, il brutto, il cattivo(1966)’, ‘10.The Lord of the Rings: The Fellowship of the Ring(2001)’, ‘11.Fight Club(1999)’, ‘12.Forrest Gump(1994)’, ‘13.Inception(2010)’, ‘14.Star Wars: Episode V - The Empire Strikes Back(1980)’, ‘15.The Lord of the Rings: The Two Towers(2002)’, ‘16.The Matrix(1999)’, ‘17.Goodfellas(1990)’, “18.One Flew Over the Cuckoo’s Nest(1975)”, ‘19.Shichinin no samurai(1954)’, ‘20.Se7en(1995)’, ‘21.La vita è bella(1997)’, ‘22.Cidade de Deus(2002)’, ‘23.The Silence of the Lambs(1991)’, “24.It’s a Wonderful Life(1946)”, ‘25.Star Wars(1977)’, ‘26.Gisaengchung(2019)’, ‘27.Saving Private Ryan(1998)’, ‘28.Sen to Chihiro no kamikakushi(2001)’, ‘29.The Green Mile(1999)’, ‘30.Interstellar(2014)’, ‘31.Léon(1994)’, ‘32.The Usual Suspects(1995)’, ‘33.Seppuku(1962)’, ‘34.The Lion King(1994)’, ‘35.American History X(1998)’, ‘36.The Pianist(2002)’, ‘37.Terminator 2: Judgment Day(1991)’, ‘38.Back to the Future(1985)’, ‘39.Modern Times(1936)’, ‘40.Psycho(1960)’, ‘41.Gladiator(2000)’, ‘42.City Lights(1931)’, ‘43.The Departed(2006)’, ‘44.The Intouchables(2011)’, ‘45.Whiplash(2014)’, ‘46.The Prestige(2006)’, ‘47.Once Upon a Time in the West(1968)’, ‘48.Hotaru no haka(1988)’, ‘49.Casablanca(1942)’, ‘50.Joker(2019)’, ‘51.Nuovo Cinema Paradiso(1988)’, ‘52.Rear Window(1954)’, ‘53.Alien(1979)’, ‘54.Apocalypse Now(1979)’, ‘55.Memento(2000)’, ‘56.Raiders of the Lost Ark(1981)’, ‘57.The Great Dictator(1940)’, ‘58.The Lives of Others(2006)’, ‘59.Django Unchained(2012)’, ‘60.Anand(1971)’, ‘61.Paths of Glory(1957)’, ‘62.The Shining(1980)’, ‘63.Avengers: Infinity War(2018)’, ‘64.WALL·E(2008)’, ‘65.Sunset Blvd.(1950)’, ‘66.Spider-Man: Into the Spider-Verse(2018)’, ‘67.Mononoke-hime(1997)’, ‘68.Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb(1964)’, ‘69.Oldeuboi(2003)’, ‘70.Witness for the Prosecution(1957)’, ‘71.Avengers: Endgame(2019)’, ‘72.The Dark Knight Rises(2012)’, ‘73.Once Upon a Time in America(1984)’, ‘74.Aliens(1986)’, ‘75.Kimi no na wa.(2016)’, ‘76.Coco(2017)’, ‘77.American Beauty(1999)’, ‘78.Braveheart(1995)’, ‘79.Das Boot(1981)’, ‘80.3 Idiots(2009)’, ‘81.Toy Story(1995)’, ‘82.1917(2019)’, ‘83.Tengoku to jigoku(1963)’, ‘84.Taare Zameen Par(2007)’, ‘85.Star Wars: Episode VI - Return of the Jedi(1983)’, ‘86.Amadeus(1984)’, ‘87.Reservoir Dogs(1992)’, ‘88.Inglourious Basterds(2009)’, ‘89.Good Will Hunting(1997)’, ‘90.2001: A Space Odyssey(1968)’, ‘91.Vertigo(1958)’, ‘92.Requiem for a Dream(2000)’,
‘93.M - Eine Stadt sucht einen Mörder(1931)’, ‘94.Dangal(2016)’, ‘95.Eternal Sunshine of the Spotless Mind(2004)’, ‘96.Citizen Kane(1941)’, ‘97.Capharnaüm(2018)’, ‘98.Jagten(2012)’, ‘99.Full Metal Jacket(1987)’, ‘100.North by Northwest(1959)’, ‘101.A Clockwork Orange(1971)’, ‘102.Ladri di biciclette(1948)’, ‘103.The Kid(1921)’, ‘104.Snatch(2000)’, “105.Singin’ in the Rain(1952)”, ‘106.Scarface(1983)’, ‘107.Taxi Driver(1976)’, ‘108.Amélie(2001)’, ‘109.Lawrence of Arabia(1962)’, ‘110.The Sting(1973)’, ‘111.Toy Story 3(2010)’, ‘112.Metropolis(1927)’, ‘113.Ikiru(1952)’, ‘114.Per qualche dollaro in più(1965)’, ‘115.Jodaeiye Nader az Simin(2011)’, ‘116.Double Indemnity(1944)’, ‘117.The Apartment(1960)’, ‘118.Incendies(2010)’, ‘119.To Kill a Mockingbird(1962)’, ‘120.Indiana Jones and the Last Crusade(1989)’, ‘121.Up(2009)’, ‘122.L.A. Confidential(1997)’, ‘123.Heat(1995)’, ‘124.Monty Python and the Holy Grail(1975)’, ‘125.Die Hard(1988)’, ‘126.Rashômon(1950)’, ‘127.Yôjinbô(1961)’, ‘128.Batman Begins(2005)’, ‘129.Idi i smotri(1985)’, ‘130.Green Book(2018)’, ‘131.Bacheha-Ye aseman(1997)’, ‘132.Der Untergang(2004)’, ‘133.Unforgiven(1992)’, ‘134.Some Like It Hot(1959)’, ‘135.Hauru no ugoku shiro(2004)’, ‘136.Ran(1985)’, ‘137.The Great Escape(1963)’, ‘138.All About Eve(1950)’, ‘139.A Beautiful Mind(2001)’, ‘140.Casino(1995)’, “141.Pan’s Labyrinth(2006)”, ‘142.Tonari no Totoro(1988)’, ‘143.El secreto de sus ojos(2009)’, ‘144.Lock, Stock and Two Smoking Barrels(1998)’, ‘145.Raging Bull(1980)’, ‘146.The Wolf of Wall Street(2013)’, ‘147.Judgment at Nuremberg(1961)’, ‘148.The Treasure of the Sierra Madre(1948)’, ‘149.There Will Be Blood(2007)’, ‘150.Babam ve Oglum(2005)’, ‘151.Three Billboards Outside Ebbing, Missouri(2017)’, ‘152.The Gold Rush(1925)’, ‘153.Chinatown(1974)’, ‘154.Dial M for Murder(1954)’, ‘155.V for Vendetta(2005)’, ‘156.Det sjunde inseglet(1957)’, ‘157.No Country for Old Men(2007)’, ‘158.Inside Out(2015)’, ‘159.Warrior(2011)’, ‘160.Shutter Island(2010)’, ‘161.Trainspotting(1996)’, ‘162.The Elephant Man(1980)’, ‘163.The Sixth Sense(1999)’, ‘164.The Thing(1982)’, ‘165.Gone with the Wind(1939)’, ‘166.Room(2015)’, ‘167.Jurassic Park(1993)’, ‘168.Smultronstället(1957)’, ‘169.Blade Runner(1982)’, ‘170.The Bridge on the River Kwai(1957)’, ‘171.Finding Nemo(2003)’, ‘172.Stalker(1979)’, ‘173.On the Waterfront(1954)’, ‘174.The Third Man(1949)’, ‘175.Fargo(1996)’, ‘176.Kill Bill: Vol. 1(2003)’, ‘177.The Truman Show(1998)’, ‘178.Gran Torino(2008)’, ‘179.Tôkyô monogatari(1953)’, ‘180.The Deer Hunter(1978)’, ‘181.Salinui chueok(2003)’, ‘182.Relatos salvajes(2014)’, ‘183.Klaus(2019)’, ‘184.Andhadhun(2018)’, ‘185.Eskiya(1996)’, ‘186.The Big Lebowski(1998)’, ‘187.Mary and Max(2009)’, ‘188.In the Name of the Father(1993)’, ‘189.Gone Girl(2014)’, ‘190.To Be or Not to Be(1942)’, ‘191.Hacksaw Ridge(2016)’, ‘192.The Grand Budapest Hotel(2014)’, ‘193.Ford v Ferrari(2019)’, ‘194.Persona(1966)’, ‘195.Before Sunrise(1995)’, ‘196.Catch Me If You Can(2002)’, ‘197.How to Train Your Dragon(2010)’, ‘198.The General(1926)’, ‘199.Mr. Smith Goes to Washington(1939)’, ‘200.Sherlock Jr.(1924)’, ‘201.Prisoners(2013)’, ‘202.12 Years a Slave(2013)’, ‘203.Cool Hand Luke(1967)’, ‘204.Mad Max: Fury Road(2015)’, ‘205.Barry Lyndon(1975)’, ‘206.Le salaire de la peur(1953)’, ‘207.Network(1976)’, ‘208.Stand by Me(1986)’, ‘209.Into the Wild(2007)’, ‘210.Million Dollar Baby(2004)’, ‘211.Life of Brian(1979)’, “212.Hachi: A Dog’s Tale(2009)”, ‘213.Platoon(1986)’, ‘214.Ben-Hur(1959)’, ‘215.Rush(2013)’, “216.La passion de Jeanne d’Arc(1928)”, ‘217.Logan(2017)’, ‘218.Dead Poets Society(1989)’, ‘219.Harry Potter and the Deathly Hallows: Part 2(2011)’, ‘220.Andrei Rublev(1966)’, ‘221.Les quatre cents coups(1959)’, ‘222.Hotel Rwanda(2004)’, ‘223.Amores perros(2000)’, ‘224.Rang De Basanti(2006)’, ‘225.Spotlight(2015)’, ‘226.Kaze no tani no Naushika(1984)’, ‘227.Ah-ga-ssi(2016)’, ‘228.Rocky(1976)’, ‘229.Rebecca(1940)’, ‘230.Portrait de la jeune fille en feu(2019)’, ‘231.Monsters, Inc.(2001)’, ‘232.La haine(1995)’, ‘233.It Happened One Night(1934)’, ‘234.Gangs of Wasseypur(2012)’, ‘235.Faa yeung nin wa(2000)’, ‘236.Baefore Sunset(2004)’, ‘237.The Princess Bride(1987)’, ‘238.The Help(2011)’, ‘239.Paris, Texas(1984)’, ‘240.Contratiempo(2016)’, ‘241.Drishyam(2015)’, ‘242.Ace in the Hole(1951)’, ‘243.The Terminator(1984)’, ‘244.Lagaan: Once Upon a Time in India(2001)’, ‘245.Kis Uykusu(2014)’, ‘246.Butch Cassidy and the Sundance Kid(1969)’, ‘247.PK(2014)’, ‘248.Aladdin(1992)’, ‘249.Akira(1988)’, ‘250.The Red Shoes(1948)’]

Puanlar :
[‘9.2’, ‘9.1’, ‘9.0’, ‘9.0’, ‘8.9’, ‘8.9’, ‘8.9’, ‘8.8’, ‘8.8’, ‘8.8’, ‘8.8’, ‘8.8’, ‘8.7’, ‘8.7’, ‘8.7’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.6’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.5’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.4’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.3’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.2’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.1’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’, ‘8.0’]

basliklar = ['1.The Shawshank Redemption(1994)', '2.The Godfather(1972)', '3.The Godfather: Part II(1974)']
puanlar = ['9.2', '9.1', '9.0']

#  Terminator 2: Judgment Day(1991)                       Filmin Ratingi 8.5
#  123456789 123456789 123456789 123456789 123456789 12345

for isim, puan in zip(basliklar, puanlar):
    isim = isim.split('.', 1)[1]
    print(" %-55s Filmin Ratingi %s" % (isim, puan))

%'li usul POSIX standardi ama Python’cular sevmiyor. Biri gelip Python’a ozel yontemini soyler herhalde.

2 Beğeni

Şöyle de yapılabilir:

max_len = max(len(i) for i in basliklar)
for isim, puan in zip(basliklar, puanlar):
    isim = isim.split('.', 1)[1]
    print(f"{isim}{' ' * (max_len - len(isim))} Filmin Ratingi: {puan}")
1 Beğeni

Ben de şöyle bir şey bırakayım

import requests 
from bs4 import BeautifulSoup

url = "https://www.imdb.com/chart/top"

site_cekimi = requests.get(url)

html_iceriği = site_cekimi.content

soup = BeautifulSoup(html_iceriği,"html.parser")

flmlr = soup.findAll("tbody",attrs={"class":"lister-list"})

sayi =0
while sayi<250:
	for i in flmlr:
		film =i.findAll("td",attrs={"class":"titleColumn"})[sayi].text.strip().replace("\n","")
		puan =i.findAll("td",attrs={"class":"ratingColumn imdbRating"})[sayi].text.strip().replace("\n","")
		print("{:<70}Filmin Ratingi: {}".format(film,puan))
	
	sayi +=1
1 Beğeni

Kendimi geliştirmek açısından hepinizin yazdığı kodları anlayıp çalıştırmaya çalışacağım. Her birinize ayrı ayrı teşekkür ederim.

En uzun ismin uzunluğunu bulup bunu değişken olarak tutuyor ardından diğer isimlerin sonuna bu değişkenin uzunluğuna denk olana kadar boşluk karakteri koyuyor.
Doğru mudur hocam? Python bilmiyorum ama bu tarz bi şey anladım da.

Sevip sevmemek ile alakası yok.

“.format()” biçimlendirme özelliği Python’a sonradan eklendi.

Ondan önce(Python 2) herkes “Unix” tarzı biçimlendirme yöntemini kullanıyordu.

Tamam işte, bir alternatif gelince bunun kullanılma oranı azaldı. Bu bir tercih olduğu için sevip sevmemekle alakası olması gayet mümkün.

Bu tarz yorumlarını anlayamıyorum. Bir konuyu tam olarak araştırmadan lütfen buraya yazma.

Öncelikle Python dilinin tercih edilme sebebi kolay yazılabilir olmasıdır.

Unix tarzı biçimlendirme yönteminde herhangi bir string’i veya bir başka veri tipini biçimlendirmek için farklı harfler bulunuyor.

Bir örnek yapayım bu konu hakkında daha fazla da tartışmak istemiyorum;
%d integer(tam sayı) değerleri için kullanılır.

string_1 = "frequenter"

print("%d" %(string_1))

#TypeError: %d format : a number is required , not str
string_1 = "frequenter"

print("{}".format(string_1))

Gördüğün gibi veri tipi farketmeksizin rahatça biçimlendirebiliyorum.

Bayağı sevip sevmemek ile alakalıymış.

Ben bunu rahat olan şeyi sevmek olarak yorumluyorum, ayrıca rahatlık ve sevmek öznel olduğu için siz “Sevip sevmemek ile alakası yok.” gibi kesin bir yargı belirtirken ben “sevip sevmemekle alakası olması gayet mümkün.” dedim.

Ben de sizin öznel yorumlara niçin ortada yanlış bir bilgi varmış gibi karşı çıktığınızı anlamadım.

Neden böyle bir alternatif çıkarıldığının sebepleri yer alıyor.

1 Beğeni

@muratdemirkiran

Aynen öyle. :slight_smile: