Parse a price table and obey robots.txt
Fill in parse_table(html). It reads the HTML text and returns a list with one dictionary per data row of <table class="prices">, shaped {"name": ..., "price": ...}. Skip the first (header) row. name is the cell text with extra spaces removed (" Green Tea " becomes "Green Tea"). price is a float made from text like Rs 1,299 (which becomes 1299.0).
Fill in allowed(robots_lines, agent, url). robots_lines is the list of lines of a robots.txt file. Use urllib.robotparser and return True if agent may fetch url, otherwise False.
The last line of the starter already prints the number of rows parsed from the sample page. Leave it, and it should print 2.
What Check tests
parse_tablereturns two rows- Names are cleaned
- Prices become floats
- A blocked path is refused
- An open path is allowed
- The program prints 2
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Output
Press Run to see what your program prints.