Extract All Links
Easypython
Given a set of URLs, build a small HTML page containing one <a> tag per URL, then extract and print every href value.
Approach: construct the HTML with one anchor tag per URL, parse it, find every <a> tag, and read each one's href attribute.
Input: First line: the number of links n. Next n lines: one URL each.
Output: One line per link: its URL.
Example 1
Input
2 https://example.com https://test.com
Output
https://example.com https://test.com
- 1 <= n <= 100
Hint 1
soup.find_all("a") returns every anchor tag in the parsed HTML.
Hint 2
element.get("href") reads the value of that element's href attribute.
Building one <a href="..."> tag per URL recreates a page full of links from the input. soup.findall("a") returns every anchor element, and link.get("href") on each one reads the URL out of its href attribute, exactly as .findall("a") + .get("href") is used in the notes.