<jupyter_start><jupyter_text>Proyecto final - Obtención de datos <NAME>, <NAME> y <NAME>  Web Scrapping<jupyter_code># Importo Beautiful Soup
from bs4 import BeautifulSoup
# Importo requests para pillar el código html de donde quiera
import requests
web = requests.get('https://www.metagamevgc.com/team-compendium/2019/12/16/vgc-2020-sword-and-shield-team-compendium')
soup = BeautifulSoup(web.content, 'html.parser')
# Cogemos la Pokédex
webDex = requests.get('https://pokemondb.net/pokedex/national')
dexSoup  = BeautifulSoup(webDex.content, 'html.parser')
pokedex = {}
types = [['itype', 'grass'], ['itype', 'poison'], ['itype', 'fire'], ['itype', 'flying'], ['itype', 'water'], 
         ['itype', 'bug'], ['itype', 'normal'], ['itype', 'electric'], ['itype', 'ground'], ['itype', 'fairy'], 
         ['itype', 'fighting'], ['itype', 'psychic'], ['itype', 'rock'], ['itype', 'steel'], 
         ['itype', 'ice'], ['itype', 'ghost'], ['itype', 'dark'], ['itype', 'dragon']]

for name in dexSoup.find_all('a'):
    if name.get('class') == ['ent-name']:
        pok = name.get_text()
        pokedex[pok] = {'type1' : 'None', 'type2' : 'None'}
    if name.get('class') in types:
        if pokedex[pok]['type1'] == 'None':
            pokedex[pok]['type1'] = name.get_text()
        else:
            pokedex[pok]['type2'] = name.get_text()
types = [['type-grass'], ['type-water'], ['type-ghost'], ['type-rock'], ['type-fire'], ['type-ground'], ['type-normal'], 
        ['type-flying'], ['type-fighting'], ['type-bug'], ['type-dragon'], ['type-dark'], ['type-fairy'], ['type-electric'],
         ['type-ice'], ['type-psychic'], ['type-steel'], ['type-poison']]


pokepasteList = []
teamList = []

for paste in soup.find_all('a'):
    if paste.get_text().lower() == 'pokepaste' :
        pokepasteList.append(paste.get('href'))

        team = []

        pag = requests.get(paste.get('href'))
        pokesoup = BeautifulSoup(pag.content, 'html.parser')

        for pok in pokesoup.find_all('pre'):
            pokplit = pok.get_text().split(' ')
            pokplit = pokplit[0].split('-')

            if pokplit[0] in pokedex :
                team.append(pokplit[0])

        teamList.append(team)
print(len(teamList))
for team in teamList:
    print(len(team))
print(len(pokepasteList))
for link in pokepasteList:
    print(link)<jupyter_output>64
https://pokepast.es/a8394695fa2dd781
https://pokepast.es/22f95fff7e1256b1
https://pokepast.es/7086cc0c2c13c136
https://pokepast.es/c3a98a31b461241f
https://pokepast.es/a3ef93cdf0f97bdc
https://pokepast.es/7b57982bc1c880ba
https://pokepast.es/464b95e5d28d660e
https://pokepast.es/de987aa62e2c7697
https://pokepast.es/af2e8abc639ebec9
https://pokepast.es/bd829ff6e51d280d
https://pokepast.es/9cb3e92b5ccad33c
https://pokepast.es/164facfc3c6c09d6
https://pokepast.es/aab39445891fa427
https://pokepast.es/61148c81c1a261f1
https://pokepast.es/799d70c61dd19b8a
https://pokepast.es/2b17b4b53999a333
https://pokepast.es/1c915d5702a31138
https://pokepast.es/e712c43f45faae1e
https://pokepast.es/ed1461a98d00bdea
https://pokepast.es/03541366ba299453
https://pokepast.es/de235819f4d7582d
https://pokepast.es/482b387b16d4b5ac
https://pokepast.es/409884f19d420632
https://pokepast.es/86d980254a647d6e
https://pokepast.es/364231897a3d453a
https://pokepast.es/106d83859807628f
https://pokepast.es/beff1a6aae2c66c[...]<jupyter_text>Construcción de la red<jupyter_code>import networkx as nx
import itertools as it
G = nx.Graph()
apariciones = {}
for team in teamList:
    for pok in team:
        if(pok in apariciones):
            apariciones[pok] += 1
        else:
            apariciones[pok] = 1
        G.add_node(pok, type1 = pokedex[pok]['type1'], type2 = pokedex[pok]['type2'])
        
        
edgeList = []
for team in teamList:
    edgeList.append([x for x in it.combinations(team, 2)])

for perm in edgeList :
    for pokPair in perm :
        if G.has_edge(pokPair[0], pokPair[1]):
            G[pokPair[0]][pokPair[1]]['weight'] += 1
        else:
            G.add_edge(pokPair[0], pokPair[1], weight = 1)
G.edges.data('weight')
#for team in teamList:
#    for pok in team:
#        G.add_node(pok)
#edgeList = []
#for team in teamList:
#    edgeList.append([x for x in it.permutations(team, 2)])
#for perm in edgeList :
#    for pokPair in perm :
#        G.add_edge(pokPair[0], pokPair[1])
nx.draw(G)
for pok in G.nodes :
    G.nodes[pok]['teams'] = apariciones[pok]
nx.write_gexf(G, "Gen8.gexf", version="1.2draft")
#apar = {}
#for team in teamList:
#    for pok in team:
#        if pok in apar :
#            apar[pok] = apar[pok] + 1
#        else :
#            apar[pok] = 1
#print(apar)<jupyter_output>{'Tyranitar': 10, 'Excadrill': 4, 'Braviary': 3, 'Hydreigon': 3, 'Mimikyu': 3, 'Rotom': 6, 'Arcanine': 11, 'Dracovish': 4, 'Darmanitan': 1, 'Milotic': 2, 'Grimmsnarl': 2, 'Togekiss': 15, 'Gyarados': 2, 'Whimsicott': 11, 'Dragapult': 11, 'Gastrodon': 6, 'Corviknight': 9, 'Politoed': 13, 'Kingdra': 10, 'Duraludon': 7, 'Rillaboom': 16, 'Scizor': 3, 'Toxtricity': 1, 'Amoonguss': 19, 'Talonflame': 7, 'Porygon2': 12, 'Rhyperior': 2, 'Urshifu': 13, 'Snorlax': 2, 'Magnezone': 2, 'Hitmontop': 2, 'Ludicolo': 1, 'Escavalier': 1, 'Volcarona': 4, 'Dusclops': 13, 'Conkeldurr': 3, 'Toxicroak': 1, 'Mandibuzz': 1, 'Clefairy': 4, 'Hatterene': 7, 'Indeedee': 12, 'Marowak': 7, 'Gigalith': 2, 'Alakazam': 3, 'Azumarill': 5, 'Dhelmise': 2, 'Slowbro': 6, 'Venusaur': 3, 'Torkoal': 4, 'Incineroar': 12, 'Terrakion': 3, 'Chandelure': 1, 'Cobalion': 2, 'Primarina': 8, 'Ferrothorn': 4, 'Charizard': 3, 'Riolu': 3, 'Cinderace': 8, 'Luxray': 2, 'Kangaskhan': 1, 'Mudsdale': 1, 'Bisharp': 2, 'Mienshao': 1, 'Sylveon': 6,[...]
{'fraction_non_alphanumeric': 0.19390093424995594, 'fraction_numerical': 0.07086197778952935, 'mean_word_length': 3.994718309859155, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 29, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '316895', 'license': 'MIT', 'n_tokens_mistral': 2627, 'n_tokens_neox': 2320, 'n_words': 446, 'path': 'Optativas/SOC/Proyecto Final/Jupyter Notebooks/Gen8Jupyter.ipynb', 'repo_name': 'PabloAvg/Practicas-FDI-UCM', 'size': '5722'}