Python 3.7 AttributeError: 'str' object has no attribute 'append'

Camarasama Posts 32 Registration date Friday November 14, 2014 Status Member Last seen November 11, 2018 - Updated on Nov 12, 2018 at 09:50 AM
 Blocked Profile - Nov 12, 2018 at 04:54 PM
Greetings, please can you help me on the below issue?
am a self learner of python and having issue debugging the below code.
get below the error i get:
AttributeError Traceback (most recent call last)
<ipython-input-98-c194ce619f5f> in <module>()
30 #extract the League Point
31 TierInfoLPs = page_html.find('span', class_="LeaguePoints").text
---> 32 TierInfoLPs.append(TierInfoLP)
34 # extract the Total Rank

AttributeError: 'str' object has no attribute 'append'
also when i don't put append methode, the result in the dataframe at the colonne of TierInfoLP, it comes with spaces, how to remove the spaces?

Thank you for your help.

# import library
from requests import get
from bs4 import BeautifulSoup as bs
import pandas as pd
from time import time
from time import sleep
from random import randint
from IPython.display import clear_output
from warnings import warn

# declaration variables
SumNames = ["camarasama", "mefisto225", "Saber+Milena"]
TotalRank = []
Tier_Rank = []
TierInfoLP = []
wins = []
losses = []
winratio = []

# creation of the loops
start_time = time()
requests = 0

# requests for the page
for name in SumNames:
response = get(''+ name)

# break between requests

# information about the requests
requests += 1
elapsed_time = time() - start_time
print('Request: {}; Frequency: {} requests/s'.format(requests, requests/elapsed_time))
clear_output(wait = True)

# if response != 200
if response.status_code != 200:
warn('Request: {}; Status code: {}'.format(requests, response.status_code))

# extract the page
page_html = bs(response.text, 'html.parser')

# select the summoner container information
summoners_infos = page_html.find_all('div', class_="tabItem")
SumName = name

# Retreiving Summoner information
#create loop to retreive information
for summoner_info in summoners_infos:

#extract the League Point
TierInfoLPs = page_html.find('span', class_="LeaguePoints").text

# extract the Total Rank
TotalRanks = page_html.find('span', class_="ranking").text

# extract the Tier Rank
Tier_Ranks = int(page_html.find('span', class_="tierRank").text)

# extract the wins
win = page_html.find('span', class_="wins").text

# extract the losses
losse = page_html.find('span', class_="losses").text

# extract the winratio
winratios = page_html.find('span', class_="winratio").text
# print(winratio)
#display Data
player_data = pd.DataFrame({
'Nom Invocateur': [SumName],
'Rank Total': [TotalRank],
'Helo': [Tier_Rank],
'Nbre de Points': [TierInfoLP],
'Nbre Victoire': [wins],
'Nbre Defaite': [losses],
'Ratio Victoire': [winratio]

1 reply

Blocked Profile
Nov 12, 2018 at 04:54 PM
Save the string as another variable, alter it, and write it back. Don't try to write it back on the same calculation you are changing it.