-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbsoup.py
More file actions
24 lines (22 loc) · 779 Bytes
/
bsoup.py
File metadata and controls
24 lines (22 loc) · 779 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
import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter - ')
position = int(input("Enter position:")) - 1
count = int(input("Enter count:"))
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, 'html.parser')
Sequence = []
tags = soup('a')
for i in range(count):
link = tags[position].get('href', None)
print("Retrieving:", link)
Sequence.append(tags[position].contents[0])
html = urllib.request.urlopen(link, context=ctx).read()
soup = BeautifulSoup(html, 'html.parser')
tags = soup('a')
link = tags[position].get('href', None)
print(Sequence[1])