forked from epequeno/python-for-informatics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04.py
More file actions
25 lines (19 loc) · 674 Bytes
/
04.py
File metadata and controls
25 lines (19 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# -*- coding: utf-8 -*-
"""
Created on Thu Jul 24 16:12:27 2014
@author: Estevan Adrian Pequeno
"""
'''
Change the urllinks.py program to extract and count paragraph (p) tags from
the retrieved HTML document and display the count of the paragraphs as the
output of your program. Do not display the paragraph text - only count them.
Test your program on several small web pages as well as some larger web pages.
'''
import re
import requests
url = raw_input("Enter url: ")
req = requests.get(url)
pattern = re.compile('<p>')
matches = [line for line in req.iter_lines()
if re.search(pattern, line)]
print "There are %d <p> tag(s) @ %s" % (len(matches), url)