Click here to Skip to main content
14,453,025 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi im new to python and i'm struggling i don't know where to start i want to add a different prefix to each line .


the output im getting now :

[reader]
label                         = free.freeccamserver.com 23011
protocol                      = cccam
user                          = 
6sbnlf free
group                         = 1
cccversion                    = 2.3.0


and this is what i want :

[reader]
label                         = free.buyiptvcode.com
protocol                      = cccam
device                        = free.buyiptvcode.com,25668
user                          = cqb7f0
password                      = free
group                         = 1
cccversion                    = 2.3.0


What I have tried:

from builtins import int
    from collections import defaultdict
    from bs4 import BeautifulSoup as soup
    import requests
    from urllib.request import urlopen as uReq
    import string

    ####################################################################################
    ########### HERE IS THE URLS
    urls=['http://freeccamserver.com/free/get2.php','https://cccamz.com/FREEN12/new0.php']
    ##########
    ls=[]
    ####################################################################################
    def getURLS(urls):
            for url in urls:
                    test = uReq(url ,timeout=100)
                    html =  test.read()
                    pg = soup(html,'lxml')


    res = (pg.h1.text)
                splite = res.replace("C:","[reader]"+"\n"+"label                       
      =")
                release = re.sub(r"(?<=\d)\s+","\n"+"protocol                      
   = cccam"+"\n"+"user                          = "+"\n" , splite)
                all = release.replace("\r","\n"+"group                         = 
   1"+"\n"+"cccversion                    = 2.3.0"+"\n")
                    ls.append(all)

            return ls
    getURLS(urls)

    for data in (ls):
            print( data)
Posted
Updated 30-Jan-20 10:47am
v5
Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
Adding a prefix to string Python

Don't know exactly what you want:
Python Strings[^]
Python String join() Method[^]
   
v2
Comments
ziko-ZR1 22-Jan-20 12:43pm
   
i want to put different strings in each position i want
Patrice T 22-Jan-20 13:51pm
   
you need to explain in detail what you want.
Use Improve question to update your question.
ziko-ZR1 22-Jan-20 14:05pm
   
Thanks for your help
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi:)

I hope this helps you out?

greetings Johan

"""
HI:)

Is it a program u want to alter a bit to fit your needs and the pay off is other than learning python?
If so, I wish i could help without asking you to waste effort with doing python but I dont know enough
python to fully understand the program. (No sarcasm or insult intended)

Heres an example if you want it?
"""

"""
Between three quote marks gets lifted out of the program and is means of communication between programmers
"""

#After hashtag is comments, dosent affect how the program behaves. Also programmer communication.

print("prefix."+"string"+".suffix")#Three "strings" added to each other with +
integer = 10 #integer is a variable name thats given an integer value of 10 at the beginning of this row. 10 gets assigned to integer variable name from right to left
string = str(integer)# str() is a function that converts to string
print(string)#Strings can be attatched with +
integer = int(string)#int() is a function that converts to integer
print(integer)#Can be calculated with

"""
Strings as this comment have no integer meaning for calculating
Sometimes i change back and forth between strings and integer using
str()
and
int()
To get the desired result
"""


This is what running the program looks like
RESTART: C:/Users/Hacke/AppData/Local/Programs/Python/Python37/CodeProject/Adding a prefix to string Python.py
prefix.string.suffix
10
10
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100