<jupyter_start><jupyter_text>XML - Transform sitemap to dataframe **Tags:** xml file tool operations automation dataframe **Author:** [<NAME>](https://www.linkedin.com/in/ACoAAAJHE7sB5OxuKHuzguZ9L6lfDHqw--cdnJg/)  Input  Import library<jupyter_code>import naas
import json 
try:
    import xmltodict
except:
    !pip install xmltodict
    import xmltodict
import pandas as pd
import requests<jupyter_output><empty_output><jupyter_text>Choose the website you want<jupyter_code>website = "https://zapier.com"<jupyter_output><empty_output><jupyter_text>Model  Get your Dataframe<jupyter_code>def sitemap_to_df(url):
    df = None
    key = "urlset.url.url"
    r = requests.get(f'{url}/sitemap.xml')
    data_dict = xmltodict.parse(r.content) 
    if key and len(key.split('.')) > 0:
        keys = key.split('.')
        keys.reverse()
        data = data_dict.get(keys.pop())
        while(len(keys) > 1):
            data = data.get(keys.pop())
        df = pd.DataFrame.from_dict(data=data)
    elif key and data_dict.get(key):
        df = pd.DataFrame.from_dict(data=data_dict.get(key))
    else:
        df = pd.DataFrame.from_dict(data=data_dict)
    return df
df = sitemap_to_df(website)<jupyter_output><empty_output><jupyter_text>Output  Display result<jupyter_code>df<jupyter_output><empty_output><jupyter_text>Set the timezone<jupyter_code>naas.get_remote_timezone()
naas.set_remote_timezone("Europe/Lisbon")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12508638562543192, 'fraction_numerical': 0.00414651002073255, 'mean_word_length': 4.590733590733591, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 24, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 6}, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '25859', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 557, 'n_tokens_neox': 539, 'n_words': 86, 'path': 'XML/XML_Transform_sitemap_to_dataframe.ipynb', 'repo_name': 'krajai/testt', 'size': '1455'}