SHARE
TWEET

Untitled

a guest Apr 25th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Import urllib and BS
  2. from urllib.request import urlopen
  3. from bs4 import BeautifulSoup
  4. import ssl
  5.  
  6. ctx = ssl.create_default_context()
  7. ctx.check_hostname = False
  8. ctx.verify_mode = ssl.CERT_NONE
  9.  
  10. #Set inputs
  11. url = input('Enter URL - ')
  12.  
  13. count = input('Enter count - ')
  14. count = int(count)
  15.  
  16. position = input('Enter position - ')
  17. position = int(position)
  18.  
  19. #print(range(count))
  20. #counting loop
  21. for num in range(count + 1) :
  22.     print(num)
  23.     print('Retrieving:', url)
  24.     html = urlopen(url, context=ctx).read()
  25.     soup = BeautifulSoup(html, 'html.parser')
  26.     tags = soup('a')
  27.     for tag in tags:
  28.         #specify which attribute of element you want
  29.         link = tag.get('href')
  30.         # print(link[position - 1])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top