Skip to content

Commit ee2a0d5

Browse files
committed
added WebWordCounter script
1 parent 6bf14ba commit ee2a0d5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,9 @@ Happy scripting!
4343
#### Requirements :
4444

4545
Python 3.5+
46+
47+
### WebWordCounter
48+
A simple script that counts how many times a word appears on a web page
49+
50+
### Requirements :
51+
Python 3.5+

WebWordCounter/WebWordCounter.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
import requests
4+
import sys
5+
6+
def contador(link, palavra):
7+
print("Bem vindo ao contador de palavra")
8+
print()
9+
link = sys.argv[1]
10+
palavra = sys.argv[2]
11+
while True:
12+
try:
13+
r = requests.get(link)
14+
texto = r.text.lower()
15+
contador = texto.count(palavra.lower())
16+
print()
17+
print('{} aparece {} vezes em {}'.format(palavra, contador, link))
18+
break
19+
except (requests.exceptions.ConnectionError, IndexError):
20+
print('O link informado é inválido, verifique-o e tente novamente.')
21+
break
22+
except requests.exceptions.MissingSchema:
23+
print('Por favor insira http(s) antes do seu link.')
24+
break
25+
contador(sys.argv[1], sys.argv[2])

0 commit comments

Comments
 (0)