Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 XML parsing and generating HTML page Python 3.6
#1
is it possible to parse the XML file and generate the html page in python 3.6
i want extract the data from XML and put it needed info into html page
Quote
#2
Answer is yes, using lxml (or BeautifulSoup):

this isn't the cleanest code in town, but it uses lxml to parse XML
example: https://www.scrapehero.com/how-to-scrape...-and-lxml/
Quote
#3
(Aug-24-2018, 05:06 AM)Madhuri Wrote: is it possible to parse the XML file and generate the html page in python 3.6
i want extract the data from XML and put it needed info into html page
Yes it possible,it depend of the HTML is already generated and have a server running.

Here a example that parese XML and generate HTML using jinja2.
I use jinja2 with Flask(jinja2 is build in) for sending stuff from server to HTML.
jinja2 can also work alone as shown here.
from bs4 import BeautifulSoup
from jinja2 import Environment, FileSystemLoader

xml ='''\
<?xml version="1.0" encoding="UTF-8"?>
<note>
  <to>Tove</to>
  <from>Jani</from>
  <heading>Reminder</heading>
  <body>Don't forget me this weekend!</body>
</note>'''

# parse
soup = BeautifulSoup(xml, 'xml')
mes_from = soup.find('from').text

# Generate html
# test.html
#<h1>{{ message }}</h1>
env = Environment(loader=FileSystemLoader('templates'))
template = env.get_template('test.html')
output = template.render(message=mes_from)
print(output)
Output:
<h1>Jani</h1> # If remove .text from parsing <h1><from>Jani</from></h1>
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Can't get method to scroll down page. caarsonr 5 168 Jun-20-2019, 09:14 PM
Last Post: caarsonr
  How to send data from remotely hosted HTML form to Pi sajid 1 106 Jun-20-2019, 03:45 PM
Last Post: snippsat
  [Flask] html error 405 SheeppOSU 0 86 Jun-08-2019, 04:42 PM
Last Post: SheeppOSU
  [split] Using beautiful soup to get html attribute value moski 6 201 Jun-03-2019, 04:24 PM
Last Post: moski
  html error 404 SheeppOSU 1 114 Jun-03-2019, 02:19 PM
Last Post: heiner55
  Dashboards with html tables fstefanov 2 189 May-08-2019, 05:53 PM
Last Post: buran
  Using beautiful soup to get html attribute value graham23s 2 206 Apr-23-2019, 09:21 PM
Last Post: graham23s
  Parsing infor from scraped files. Larz60+ 2 225 Apr-12-2019, 05:06 PM
Last Post: Larz60+
  Fetching and Parsing XML Data FalseFact 3 271 Apr-01-2019, 10:21 AM
Last Post: Larz60+
  page navigation & form filling rudolphyaber 0 164 Mar-13-2019, 06:31 PM
Last Post: rudolphyaber

Forum Jump:


Users browsing this thread: 1 Guest(s)