<jupyter_start><jupyter_text><jupyter_code>import urllib
import re
from lxml.html import fragment_fromstring

#retonra liquidez corrente e P/VP nesta ordem, nomes errados nas funcoes
def margemLiquida(empresa):
    #print(empresa)
    page = urllib.request.urlopen("http://fundamentus.com.br/detalhes.php?papel="+ empresa)
    content = page.read().decode('ISO-8859-1')


    pattern = re.compile('<table class="w728".*</table>', re.DOTALL)
    
    
    reg = re.findall(pattern, content)[0]



    import pandas as pd

    dfs = pd.read_html(reg)
    df = dfs[2]
    #print(df)
    liquidezCorrenteString = df[5][9]
    precoPatrimonioString = df[3][2]
    plString = df[3][1]


    if(liquidezCorrenteString =="-" ):
       return -999999, -999999 , -999999
    liquidezCorrente = int(liquidezCorrenteString )/100
    precoPatrimonio = int(precoPatrimonioString )/100
    pl = int(plString)/100
    
    return liquidezCorrente,precoPatrimonio , pl



listaEmpresas =  ['EVEN3', 'DTEX3', 'SQIA3', 'CCPR3', 'MAPT4', 'PFRM3', 'MILS3',
       'CESP6', 'CESP5', 'CESP3', 'BTOW3', 'LPSB3', 'RDNI3', 'ECOR3',
       'TELB3', 'RCSL4', 'MSPA3', 'BAHI3', 'BTTL3', 'TESA3', 'DTCY3',
       'EMBR3', 'HBOR3', 'SUZB3', 'VVAR3', 'TCNO3', 'MNDL3', 'BIOM3',
       'BEEF3', 'TELB4', 'TCNO4', 'BRFS3', 'TECN3', 'MGEL4', 'BOBR4',
       'CRDE3', 'RANI4', 'RANI3', 'NORD3', 'BSEV3', 'TCSA3', 'SHOW3',
       'AHEB3', 'LUPA3', 'PINE4', 'BOBR3', 'ADHM3', 'GFSA3', 'BBRK3',
       'ETER3', 'APER3', 'RPMG3', 'NUTR3', 'JFEN3', 'HBTS5', 'CALI4',
       'MTIG4', 'DMMO3', 'CTKA4', 'GSHP3', 'CTKA3', 'HOOT4', 'IGBR3',
       'CEED4', 'OIBR4', 'MNPR3', 'CEED3', 'ESTR4', 'LIQO3', 'TPIS3',
       'OIBR3', 'VIVR3', 'CCXC3', 'PLAS3', 'BDLL3', 'AZEV3', 'FHER3',
       'RSID3', 'SLED3', 'MWET3', 'MWET4', 'BDLL4', 'AZEV4', 'MEND6',
       'RNEW3', 'MEND5', 'RNEW11', 'INEP3', 'INEP4', 'SLED4', 'RNEW4',
       'SNSY5', 'PDGR3', 'MMXM3', 'TEKA3', 'OSXB3', 'TEKA4', 'BBSE3',
       'BMGB11', 'BMGB4', 'CNTO3', 'CSAB4', 'IRBR3', 'NTCO3', 'VIVA3',
       'JBDU4', 'JBDU3', 'HETA4', 'CEDO4', 'CEDO3', 'ELET3', 'ELET6',
       'ELET5', 'CTNM4', 'MRFG3', 'SGPS3', 'IDNT3', 'LIGT3', 'CTNM3',
       'PMAM3', 'RSUL4', 'CTSA4', 'CTSA3', 'IDVL3', 'BNBR3', 'CRPG6',
       'CRPG5', 'FRTA3', 'BSLI3', 'CMIG4', 'BRAP3', 'TKNO4', 'CRPG3',
       'BAZA3', 'CMIG3', 'BRAP4', 'BRSR6', 'IDVL4', 'FESA4', 'ECPR3',
       'TRPL4', 'PTBL3', 'CSNA3', 'BRSR3', 'ECPR4', 'BRGE12', 'SMLS3',
       'BMEB3', 'BGIP4', 'BRSR5', 'BMEB4', 'WHRL3', 'ROMI3', 'BRDT3',
       'BBAS3', 'CRIV3', 'GPCP3', 'EALT4', 'CLSC3', 'CIEL3', 'WHRL4',
       'CEBR6', 'SOND6', 'TAEE3', 'TAEE11', 'TAEE4', 'ALUP4', 'MERC4',
       'TRPL3', 'CEBR3', 'MYPK3', 'SAPR4', 'CEBR5', 'ALUP11', 'CRIV4',
       'ENBR3', 'SAPR11', 'ELEK3', 'BRML3', 'CAML3', 'CLSC4', 'BEES3',
       'ELEK4', 'SHUL4', 'ABCB4', 'FESA3', 'PETR4', 'CGRA3', 'SBSP3',
       'CPLE6', 'BGIP3', 'BBDC3', 'PETR3', 'SANB4', 'SAPR3', 'ITUB3',
       'ITSA4', 'WIZS3', 'SANB11', 'BRGE8', 'ALUP3', 'BBDC4', 'CPLE3',
       'ITSA3', 'TIMP3', 'BRIV3', 'BEES4', 'CGRA4', 'GEPA3', 'SANB3',
       'MRVE3', 'COCE3', 'GUAR3', 'ENMT3', 'ENMT4', 'CBEE3', 'EMAE4',
       'EKTR3', 'CSMG3', 'PTNT4', 'EKTR4', 'ITUB4', 'CEPE6', 'TUPY3',
       'RPAD3', 'PEAB3', 'ATOM3', 'MTSA4', 'EEEL3', 'GEPA4', 'VLID3',
       'TGMA3', 'CSAN3', 'EUCA4', 'PEAB4', 'EEEL4', 'CEEB5', 'CGAS5',
       'CGAS3', 'VULC3', 'PSSA3', 'SPRI6', 'BRIV4', 'COCE5', 'EQTL3',
       'NEOE3', 'NEOE3', 'BRGE3', 'LEVE3', 'CAMB4', 'CEEB3', 'BAUH4',
       'TEND3', 'BRGE6', 'EALT3', 'SPRI5', 'RAPT3', 'WLMM3', 'WLMM4',
       'CPFE3', 'HGTX3', 'VIVT3', 'SLCE3', 'HYPE3', 'EGIE3', 'KEPL3',
       'BRGE11', 'JBSS3', 'HAGA4', 'BPAC5', 'UNIP6', 'PATI3', 'SPRI3',
       'VALE3', 'GOAU3', 'RPAD6', 'ENAT3', 'PATI4', 'SULA4', 'PCAR4',
       'UNIP3', 'CARD3', 'VIVT4', 'GRND3', 'UNIP5', 'TIET4', 'ENEV3',
       'CEPE5', 'GOAU4', 'CSRN6', 'PTNT3', 'POMO3', 'RAPT4', 'GGBR3',
       'CAMB3', 'BPAC11', 'CSRN3', 'TIET11', 'PCAR3', 'MOAR3', 'LLIS3',
       'RPAD5', 'SULA11', 'CSRN5', 'GGBR4', 'CVCB3', 'KLBN4', 'SEER3',
       'POMO4', 'KLBN11', 'GPIV33', 'AFLT3', 'CELP7', 'CELP5', 'GBIO33',
       'KLBN3', 'ENGI4', 'TRIS3', 'TIET3', 'UGPA3', 'ENGI11', 'YDUQ3',
       'WSON33', 'ABEV3', 'FRAS3', 'AGRO3', 'FRIO3', 'QUAL3', 'JHSF3',
       'SULA3', 'PNVL4', 'REDE3', 'LUXM4', 'BPAN4', 'DIRR3', 'ENGI3',
       'HAGA3', 'PARD3', 'BMKS3', 'SMTO3', 'UCAS3', 'MDIA3', 'JPSA3',
       'BPAC3', 'MOVI3', 'ODPV3', 'BRGE5', 'USIM6', 'FLRY3', 'CYRE3',
       'IGTA3', 'PNVL3', 'TXRX4', 'DOHL4', 'COGN3', 'USIM5', 'JSLG3',
       'B3SA3', 'USIM3', 'ARZZ3', 'EUCA3', 'LCAM3', 'SCAR3', 'BKBR3',
       'CRFB3', 'BRKM6', 'LREN3', 'BALM3', 'MULT3', 'BMIN4', 'RENT3',
       'RLOG3', 'RADL3', 'HAPV3', 'BALM4', 'RAIL3', 'AALR3', 'CCRO3',
       'LOGG3', 'BMIN3', 'OFSA3', 'TXRX3', 'BRKM5', 'WEGE3', 'DOHL3',
       'EZTC3', 'BRKM3', 'AMAR3', 'NATU3', 'PRIO3', 'CEGR3', 'ALPA3',
       'TASA3', 'POSI3', 'ALPA4', 'TASA4', 'MGLU3', 'LAME3', 'JOPA4',
       'CPRE3', 'AZUL4', 'LAME4', 'TOTS3', 'JOPA3', 'GNDI3', 'LINX3',
       'BIDI3', 'BIDI4', 'BIDI11', 'LOGN3', 'LIPR3', 'BRPR3', 'OMGE3',
       'MEAL3', 'DASA3', 'GOLL4', 'STBP3', 'ALSO3', 'ANIM3']
listaSemDados =[]
listaAprovadas =[]
listaReprovadas =[]

#listaEmpresas = ["APTI3"]

for empresa in listaEmpresas:
  #print(empresa)
  try:
      #print(empresa)
      liquidezCorrente, precoPatrimonio, pl = margemLiquida(empresa)
      if(liquidezCorrente== -999999 ):
        listaSemDados.append(empresa)
        continue 

      #liquidezCorrente = 1.5
      #precoPatrimonioCorte = 1.2
      #plCorte = 15
      
      liquidezCorrenteCorte = 1.5*0.7
      precoPatrimonioCorte = 1.2*1.3
      plCorte = 30

      if( (liquidezCorrente >= liquidezCorrenteCorte)  and  (precoPatrimonio< precoPatrimonioCorte) and (precoPatrimonio > 0) and (pl < plCorte) and (pl >0)):
          print( empresa + " Margem: " +str(liquidezCorrente) + "Patrimonio/preco: " + str(precoPatrimonio) + "PL:" + str(pl))
          listaAprovadas.append(empresa)

      else: 
          listaReprovadas.append(empresa)
  except Exception as e:
      print(empresa +" "+  str(e))
listaAprovadas
df = margemLiquida("PSSA3")
df[2][3][1]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2424778761061947, 'fraction_numerical': 0.08189863234111022, 'mean_word_length': 3.814872192099148, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '201890', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 3183, 'n_tokens_neox': 3096, 'n_words': 553, 'path': 'Fundamentus.ipynb', 'repo_name': 'lds1804/Docs', 'size': '6215'}