Question

In oython

3. HTML supports ordered and unordered lists. An ordered list is defined using element ol and each item of the list is define

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

from html.parser import HTMLParser
class ListCollector(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.flag = 0
self.ol = 0
self.data = []
self.data1 = []

def handle_starttag(self, tag, attributes):
if tag == 'ol':
self.ol = 1
if tag == 'ul':
self.ol = 2
if tag != 'li':
return
if self.flag:
self.flag += 1
return
self.flag = 1

def handle_endtag(self, tag):
if tag == 'ol' or tag == 'ul':
self.ol = 0
if tag == 'li' and self.flag:
self.flag -= 1

def handle_data(self, data):
if self.flag:
if self.ol == 2:
self.data.append(data)
elif self.ol == 1:
self.data1.append(data)
def getLists(self):
print([self.data,self.data1])

infile = open('lists.html')
content = infile.read()
infile.close()
myparse = ListCollector()
myparse.feed(content)
myparse.getLists()

output:

File main.py, line 1 rom html.parser import HTMLParser SyntaxError: invalid syntax Program finished with exit code 1 Press

Add a comment
Know the answer?
Add Answer to:
In oython 3. HTML supports ordered and unordered lists. An ordered list is defined using element ol and each item of th...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Add the following forms to the HTML grammar of Fig. 5.13: A list item must be...

    Add the following forms to the HTML grammar of Fig. 5.13: A list item must be ended by a closing tag </LI>. An element can be an unordered list, as well as an ordered list. Unordered lists are surrounded by the tag <UL> and its closing </UL>. An element can be a table. Tables are surrounded by <TABLE> and its closer </TABLE>. Inside these tags are one or more rows, each of which is surrounded by <TR> and </TR>. The...

  • Use a style sheet to define the following rules and implement the given HTML code. Please...

    Use a style sheet to define the following rules and implement the given HTML code. Please put your style information within the same file as the HTML code. Rules: • Hyperlinks using the nodec class should display no decoration. • Hyperlinks should display text in white with a green background color when the mouse pointer is held over the link. (use the hover pseudo-class) • Unordered lists not nested within any other lists should be displayed in blue text and...

  • A question regarding HTML coding. Need help from B to F. 70: A. Which type of...

    A question regarding HTML coding. Need help from B to F. 70: A. Which type of list has numbers next to each item: ordered or unordered? Ordered list or have numbers next to each item. Unordered lists or have bulletins next to them. B. What tag is used to mark a term to be defined? What tag marks the definition? C. Can you apply other tags (such as h1 headings) to list items? If so, how? If not, why not?...

  • Code for the movies page: <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />...

    Code for the movies page: <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="style.css" /> <title>Daniel's Movie Page</title> </head> <body> <a href="hobbies.html">Hobbies</a> <h1>Movies and Actors</h1> <ol> <li class="ol-list1">Gravity</li> <li>Avenger</li> <li>Marshal</li> <li>Interstellar</li> <li>Dark Knight</li> <li>Superman</li> </ol> <ul> <li class="ul-list1">Robet Downey jr.</li> <li>Sharuk Khan</li> <li>Ranbir Kapoor</li> <li>Sidhhart Malhotra</li> <li>Angela Joli</li> <li>Leonardo DiCaprio/li> </ul> <h2>Favorite Movie</h2> <p> <b>Gravity:</b> The movie portrayed what happens to an astronaut if he/she is pushed away from spaceship.It was terrifying how much...

  • 1 (25 pts.). The following HTML document (with gaps) is initially rendered as shown in the...

    1 (25 pts.). The following HTML document (with gaps) is initially rendered as shown in the first screenshot below. When the anchor JavaScript is clicked, a link is followed to the header JavaScript lower in the page, and the rendering is as shown in the next screen shot. If, on the other hand, the anchor PHP is clicked, a link is followed to the header PHP still lower in the page, and the rendering is as shown in the last...

  • Using Basic HTML CSS for a webpage content does not matter. Week 3: Assignment <nav> and...

    Using Basic HTML CSS for a webpage content does not matter. Week 3: Assignment <nav> and pseudo-classes for links Submit Assignment Due Sunday by 11:59pm Points 100 Submitting a text entry box This assignment you will upload to Coton. You will submit only your URLs to Canvas. Use the rubric as a checklist to make sure you complete everything. DO NOT copy and paste code from any source including templates, websites or examples in this class. Create your navigation as...

  • Design a program using Python and using from flask Import flask that generates a lottery number...

    Design a program using Python and using from flask Import flask that generates a lottery number but in a website.. The program should have an Integer array with 9 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 42 for each element. (Use the random function) Then write another loop that displays the contents of the array. Each number should be displayed as a list, the numbers should be generated...

  • CST 231   Web Systems         Fall 2017    Due Friday, December 8, 2017 at 11:59pm. Choose three...

    CST 231   Web Systems         Fall 2017    Due Friday, December 8, 2017 at 11:59pm. Choose three Problems Only. 100 points total 1 (25 pts.). The HTML document listed below (with gaps) is rendered as shown at right. The header at the top is an h3 element subject to a CSS rule (see below) causing its font to be Courier New. The boxed content is that of a p element whose class is box (see below), which specifies, among other things,...

  • IN PYTHON Develop the program that will allow you to obtain an ordered list of whole...

    IN PYTHON Develop the program that will allow you to obtain an ordered list of whole numbers from least to greatest from two lists of whole numbers. The individual values ​​of the input lists are captured by the user one by one and then both lists will be joined and then sorted in ascending order (from lowest to highest value). Your program should allow the capture of the entire values ​​of the lists without making use of messages (legends) to...

  • given below are the project description and their Html and css files i need javascript according...

    given below are the project description and their Html and css files i need javascript according to the project and other files! WEB230 - JavaScript 1 Assignment 6b - Event Delegation Before starting, study the HTML and open it in a browser so that you understand the structure of the document. You will add functionality to perform several tasks in our shopping list app. Clicking the red "X" at the right of an item will delete that item. Clicking on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT