I have a script that uses a Python package called arcpy_metdata. It basically allows you to get at ArcGIS metadata.
The script is set up to write the metadata to a text file and runs without errors, but unfortunately HTML code used to format the Description and Limitation items also gets written. It interferes with the readability of the textfile. I contacted the author of the package and he suggested BeautifulSoup, which leads to my question. I have this so far, but am at a loss at how to implement it:
<SPAN class="keyword token">from</SPAN> bs4 <SPAN class="keyword token">import</SPAN> BeautifulSoup
cleantext <SPAN class="operator token">=</SPAN> BeautifulSoup<SPAN class="punctuation token">(</SPAN>raw_html<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
</CODE></P><P><CODE>And here is my Metadata2Txt script:<BR />
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> arcpy_metadata <SPAN class="keyword token">as</SPAN> md
<SPAN class="keyword token">import</SPAN> re
ws <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'Database Connections\ims to Plainfield.sde\gisedit.DBO.Tax_Map_LY\gisedit.DBO.Tax_Map_Parcels_LY'</SPAN>
metadata <SPAN class="operator token">=</SPAN> md<SPAN class="punctuation token">.</SPAN>MetadataEditor<SPAN class="punctuation token">(</SPAN>ws<SPAN class="punctuation token">)</SPAN>
path <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'\\gisfile\GISstaff\Jared\Python Scripts\Test\Parcels'</SPAN>
<SPAN class="comment token">##cleantext = BeautifulSoup(raw_html).text</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">meta2txt</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
title <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>title
tags <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>tags
purpose <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>purpose
abstract <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>abstract
credits <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>credits
citation <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>citation
limitation <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>limitation
extent_description <SPAN class="operator token">=</SPAN> metadata<SPAN class="punctuation token">.</SPAN>extent_description
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>ws<SPAN class="punctuation token">)</SPAN>
sr <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>spatialReference
tf <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>path <SPAN class="operator token">+</SPAN> <SPAN class="string token">" "</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Metadata.txt"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"w"</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Metadata Content:"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"----------------------------------------------"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> title<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Title:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>title<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Title:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>title<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Title: \nThere is no title.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Title: \nThere is no title.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> tags<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Tags:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>tags<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Tags:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>tags<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Tags: \nThere are no tags.\n"</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Tags: \nThere are no tags.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> purpose<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Summary:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>purpose<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Summary:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>purpose<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Summary: \nThere is no summary.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Summary: \nThere is no summary.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> abstract<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Description:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>abstract<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Description:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>abstract<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Description: \nThere is no description.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Description: \nThere is no description.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> credits<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Credits:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>credits<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Credits:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>credits<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Credits: \nThere are no credits.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Credits: \nThere are no credits.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> citation<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Citation:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>citation<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Citation:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>citation<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Citation: \nThere is no citation.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Citation: \nThere is no citation.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> limitation<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Limitation:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>limitation<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Limitation:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>limitation<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Limitation: \nThere is no limitation.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Limitation: \nThere is no limitation.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> extent_description<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Extent:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>extent_description<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Extent:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>extent_description<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Extent: \nThere is no extent.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Extent: \nThere is no extent.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> sr<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Spatial Reference:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Spatial Reference:\n{}\n'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>sr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Spatial Reference: \nThere is no spatial reference.\n'</SPAN><SPAN class="punctuation token">)</SPAN>
tf<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Extent: \nThere is no spatial reference.\n'</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'\n'</SPAN><SPAN class="punctuation token">)</SPAN>
meta2txt<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Here's how Description item of this particular feature class looks in the textfile after running the script:
Description<SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token"><</SPAN>DIV STYLE<SPAN class="operator token">=</SPAN><SPAN class="string token">"text-align:Left;"</SPAN><SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>DIV<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>DIV<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>P<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN>SPAN<SPAN class="operator token">></SPAN>The tax map parcels layer <SPAN class="keyword token">is</SPAN> published
every year normally during the spring through the Will County Clerk Tax Extension<SPAN class="punctuation token">.</SPAN> This
layer contains various parcels within Will County<SPAN class="punctuation token">.</SPAN> The tax map parcels entered <SPAN class="keyword token">is</SPAN> only
digitized based upon plats <SPAN class="operator token">and</SPAN> recorded documents received by the Tax Extension within
the Will County Clerk Office<SPAN class="punctuation token">.</SPAN> <SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>SPAN<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>P<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>DIV<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>DIV<SPAN class="operator token">></SPAN><SPAN class="operator token"><</SPAN><SPAN class="operator token">/</SPAN>DIV<SPAN class="operator token">></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>