|
1 |
| -#USings ssl and urrlib.request to read the contents of the url |
2 |
| -#ssl helps us to avoid cretificate verifation and so on |
| 1 | +# USings ssl and urrlib.request to read the contents of the url |
| 2 | +# ssl helps us to avoid cretificate verifation and so on |
| 3 | + |
3 | 4 | import ssl
|
4 |
| -from urllib.request import urlopen,Request |
| 5 | +from urllib.request import urlopen, Request |
5 | 6 | from bs4 import BeautifulSoup
|
6 | 7 |
|
7 | 8 | ctx = ssl.create_default_context()
|
|
12 | 13 |
|
13 | 14 | Url = input("Enter your Urllink")
|
14 | 15 | try:
|
15 |
| - #trying to access the page |
16 |
| - page = Request(Url, headers = { 'User-Agent':'Mozilla/5.0' } ) |
| 16 | + # trying to access the page |
| 17 | + page = Request(Url, headers = {'User-Agent':'Mozilla/5.0'}) |
17 | 18 | page = urlopen(page, context = ctx ).read()
|
18 |
| - #Using beautifulsoup to read the contents of the page |
| 19 | + # Using beautifulsoup to read the contents of the page |
19 | 20 | soup = BeautifulSoup(page,'html.parser')
|
20 |
| - #finding all the link headers |
| 21 | + # finding all the link headers |
21 | 22 | links = soup.findAll('a')
|
22 |
| - if(links is not None): |
23 |
| - finalLinks = [ ] |
24 |
| - #getting actual site links from the header a |
25 |
| - for link in links: |
26 |
| - if 'href' in str(link): |
27 |
| - templist = str(link).split("href") |
28 |
| - index1 = templist[-1].index("\"") |
29 |
| - index2 = templist[-1][index1 + 1 : ].index("\"") |
| 23 | + if(links is not None) : |
| 24 | + finalLinks = [] |
| 25 | + # getting actual site links from the header a |
| 26 | + for link in links : |
| 27 | + if 'href' in str ( link ): |
| 28 | + templist = str ( link ).split("href") |
| 29 | + index1 = templist[ -1 ].index("\"") |
| 30 | + index2 = templist[ -1 ][ index1 + 1 : ].index( "\"" ) |
30 | 31 | finalLinks.append( templist[-1][ index1 : index2 + 3 ] )
|
31 | 32 | print("Here are your final links")
|
32 |
| - #printing the final completed list |
| 33 | + # printing the final completed list |
33 | 34 | for i in finalLinks:
|
34 | 35 | print(i)
|
35 | 36 | except Exception as e:
|
|
0 commit comments