Last active
March 25, 2023 07:25
-
-
Save thomasjk10/9db27b3c8e8d3108d90b6c293ad9dd75 to your computer and use it in GitHub Desktop.
Following links in python using Beautiful Soup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
from BeautifulSoup import * | |
URL = raw_input("Enter the URL:") #Enter main URL | |
link_line = int(raw_input("Enter position:")) - 1 #The position of link relative to first link | |
count = int(raw_input("Enter count:")) #The number of times to be repeated | |
while count >= 0: | |
html = urllib.urlopen(URL).read() | |
soup = BeautifulSoup(html) | |
tags = soup('a') | |
print URL | |
URL = tags[link_line].get("href", None) | |
count = count - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment