Created
September 18, 2016 05:04
-
-
Save donlovett/c66c8db8bd0d03026d3104e95215b9ae to your computer and use it in GitHub Desktop.
Week 4 2nd assignment
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
# 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