Advertisement
nicuf

remove connecting words from links

Jan 24th, 2022 (edited)
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. EXPLANATION:
  2.  
  3. ROMANIAN: https://neculaifantanaru.com/python-elimina-cuvintele-de-legatura-din-linkurile-html.html
  4. ENGLISH:  https://neculaifantanaru.com/en/python-removes-connecting-words-from-html-links.html
  5. -----------------------
  6.  
  7.  
  8. LINK = 'taramul-prea-indepartat-al-zacamintelor-necunoscute.html
  9. LISTA_CUVINTE_LEGATURA = [
  10.    'in', 'la', 'unei', 'si', 'sa', 'se', 'de', 'prin', 'unde', 'care', 'a',
  11.    'al', 'prea', 'lui', 'din', 'ai', 'unui', 'acei', 'un', 'doar', 'tine',
  12.    'ale', 'sau', 'dintre', 'intre', 'cu','ce', 'va', 'fi', 'este', 'cand', 'o'
  13. ]
  14.  
  15. # folosim DEF cand vrem sa definim o functie => un cuvant cheie in Python
  16. # REGULA: def nume_functie(lista_argumente)
  17.  
  18. def preia_cuvinte_link(link):
  19.    cuvinte = link.split('.')[0] # [0] ia primul element iar daca pun [1] ia al doilea element
  20.    cuvinte = cuvinte.split('-')
  21.    cuvinte_ok = list()
  22.    print("INAINTE REMOVE: ", cuvinte)
  23.    for cuv in cuvinte:
  24.        if cuv not in LISTA_CUVINTE_LEGATURA:
  25.            cuvinte_ok.append(cuv)
  26.    print("DUPA REMOVE: ", cuvinte_ok)
  27.    
  28.    return cuvinte_ok  # am pus retutn fiindca voi avea nevoie de rezultatul functiei de mai sus
  29.  
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement