Created
          April 29, 2021 20:14 
        
      - 
      
- 
        Save deobald/7c1c9f6ebae62e6b916eceb3fd373b0b to your computer and use it in GitHub Desktop. 
    Follow a link with Beautiful Soup
  
        
  
    
      This file contains hidden or 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 | |
| print URL | |
| html = urllib.urlopen(URL).read() | |
| soup = BeautifulSoup(html) | |
| tags = soup('a') | |
| follow_url = tags[link_line].get("href", None) | |
| print follow_url | |
| inner_html = urllib.urlopen(follow_url).read() | |
| inner_soup = BeautifulSoup(html) | |
| # parse the table from inner_soup | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment