Skip to content

Instantly share code, notes, and snippets.

@donlovett
Created September 18, 2016 05:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donlovett/c66c8db8bd0d03026d3104e95215b9ae to your computer and use it in GitHub Desktop.
Save donlovett/c66c8db8bd0d03026d3104e95215b9ae to your computer and use it in GitHub Desktop.
Week 4 2nd assignment
# Note - this code must run in Python 2.x and you must download
# http://www.pythonlearn.com/code/BeautifulSoup.py
# Into the same folder as this program
import urllib
from BeautifulSoup import *
countb = int(input("Enter a count: "))
position = int(input("Enter position: "))
url = 'http://python-data.dr-chuck.net/known_by_Lida.html'
x = 1
while x < countb :
#url = raw_input('Enter - ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
# Retrieve all of the anchor tags
tags = soup('a')
#for tag in tags:
countera = 0
for tag in tags:
#range (tag,tags)
countera += 1
if countera == position:
print tag.get('href', None)
url = tag.get('href', None)
print url
# Print "none"
x += 1
print ("Last name in sequence", url)
print ("Normal completion")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment