-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_position.py
42 lines (33 loc) · 1.18 KB
/
url_position.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#import libraries
import urllib.request, urllib.parse,urllib.error
from bs4 import BeautifulSoup
import re
import ssl
# ignore ssl certificate errors
certification = ssl.create_default_context()
certification.check_hostname = False
certification.verify_mode = ssl.CERT_NONE
# Enter url link
url = input('Enter URL Here: - ')
html = urllib.request.urlopen(url,context = certification).read()
soup = BeautifulSoup(html, 'html.parser')
# Retrives the url data from the specified html anchor tags.
tags = soup('a')
count = input('Enter count number: ')
count = int(count)
pos = input('Enter position number: ')
pos = int(pos)
print('Retrieving:',url)
#lookup for each anchor tags
for tag in tags:
#check the index position
if (tags.index(tag) <= pos):
tag = tag.get('href',None)
print('Retrieving:',tag)
#print('Count:',count)
count = count -1
if count < 0:
print('Red flag:',count, 'count is finish!')
break
else:
continue