valeros
May 15th, 2016, 06:51
To get all monsters from the free DM's Rules posted on the Wizards of the Coast website, you can use the powershell commands below to get an "npcs.txt" file for PAR5E for creating a module. (That will also give you a bunch of examples that work for creating your own monsters.)
Note: since this will access the WoTC website, when running this you may get one or two popups asking about cookies. You can select yes or no.
1) Open a command prompt (In Windows 10, right click the start button and select "Command Prompt")
2) In the command prompt, type or copy/paste the following:
powershell
$HTML = Invoke-WebRequest -Uri "https://dnd.wizards.com/products/tabletop/dm-basic-rules"
$monsters = ($HTML.ParsedHtml.body.getElementsByTagName('dl') | Where {$_.getAttributeNode('class').Value -eq 'monster-list'}).innerHTML
$monsters = $monsters -replace "(</TH>|</TD>|</THEAD>)`r`n", " " # For abilities (STR, DEX, etc.)
$monsters = $monsters -replace "<H5>Actions</H5>", "ACTIONS"
$monsters = $monsters -replace "<H5>Reactions</H5>", "REACTIONS"
$monsters = $monsters -replace "<H5>Legendary Actions</H5>", "LEGENDARY ACTIONS"
$monsters = $monsters -replace "<H5>|<H6>", "<h>" # For headers in lore
$monsters = $monsters -replace "</H5>|</H6>", "</h>" # For headers in lore
$monsters = $monsters -replace "<BR>", " "
$monsters = $monsters -replace "<LI>(Cantrip.|1st|2nd|3rd|.th)", '\r$1' # For spell lists
$monsters = $monsters -replace "<LI>", "" # In lore or actions (e.g., spectator & adult red dragon)
$monsters = $monsters -replace "<P class=lore>", "##;`r`n"
$monsters = $monsters -replace "</*(UL|LI|DD|OL|HR|THEAD|TR|TBODY|P|STRONG|EM|TH|TD| DIV|DD|TABLE|(P|DT|DIV|UL)([^>]*))>", ""
$monsters = $monsters -replace "`r`n(`r`n)+", "`r`n" # remove blank lines
$monsters = $monsters -replace " CHA `r`n", " CHA " # remove line between ability description & values
$monsters = $monsters -replace "<SPAN>([^>]+)</SPAN>", "`r`n`$1" # Make sure blank line before monster name
$monsters | Out-File -encoding UTF8 "npcs.txt"
You now have an "npcs.txt" file that you can copy into your PAR5E input directory.
Note: since this will access the WoTC website, when running this you may get one or two popups asking about cookies. You can select yes or no.
1) Open a command prompt (In Windows 10, right click the start button and select "Command Prompt")
2) In the command prompt, type or copy/paste the following:
powershell
$HTML = Invoke-WebRequest -Uri "https://dnd.wizards.com/products/tabletop/dm-basic-rules"
$monsters = ($HTML.ParsedHtml.body.getElementsByTagName('dl') | Where {$_.getAttributeNode('class').Value -eq 'monster-list'}).innerHTML
$monsters = $monsters -replace "(</TH>|</TD>|</THEAD>)`r`n", " " # For abilities (STR, DEX, etc.)
$monsters = $monsters -replace "<H5>Actions</H5>", "ACTIONS"
$monsters = $monsters -replace "<H5>Reactions</H5>", "REACTIONS"
$monsters = $monsters -replace "<H5>Legendary Actions</H5>", "LEGENDARY ACTIONS"
$monsters = $monsters -replace "<H5>|<H6>", "<h>" # For headers in lore
$monsters = $monsters -replace "</H5>|</H6>", "</h>" # For headers in lore
$monsters = $monsters -replace "<BR>", " "
$monsters = $monsters -replace "<LI>(Cantrip.|1st|2nd|3rd|.th)", '\r$1' # For spell lists
$monsters = $monsters -replace "<LI>", "" # In lore or actions (e.g., spectator & adult red dragon)
$monsters = $monsters -replace "<P class=lore>", "##;`r`n"
$monsters = $monsters -replace "</*(UL|LI|DD|OL|HR|THEAD|TR|TBODY|P|STRONG|EM|TH|TD| DIV|DD|TABLE|(P|DT|DIV|UL)([^>]*))>", ""
$monsters = $monsters -replace "`r`n(`r`n)+", "`r`n" # remove blank lines
$monsters = $monsters -replace " CHA `r`n", " CHA " # remove line between ability description & values
$monsters = $monsters -replace "<SPAN>([^>]+)</SPAN>", "`r`n`$1" # Make sure blank line before monster name
$monsters | Out-File -encoding UTF8 "npcs.txt"
You now have an "npcs.txt" file that you can copy into your PAR5E input directory.