I have a list in a file, where each line has a user agent (with "at the beginning and at the end of each line), which is used in a later part of a program, to perform automated tests using selenium. When I opened the list, I implemented that, for each line read, I would remove the first and last character from each line as follows:
USER_AGENTS_FILE = './users.txt'
RUNNING = True
def LoadUserAgents(uafile=USER_AGENTS_FILE):
uas = [ ]
with open(uafile, 'rb' ) as uaf:
for ua in uaf.readlines():
if ua:
uas.append(ua.strip()[1:-1-1])
random.shuffle(uas)
return uas
uas = LoadUserAgents()
Adding also the feature to randomly pick rows. However, when I try to display the list by the following command:
for i in range(0,10):
print(random.choice(uas))
I get something like the following:
b'Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.8.1.6) Gecko/20070731 BonEcho/2.0.0.'
When you actually need to get:
Mozilla/5.0 (BeOS; U; BeOS BePC; en-US; rv:1.8.1.6) Gecko/20070731 BonEcho/2.0.0.
Could anyone help me solve this problem?