In Python, how do I .find the '#'

I am trying to write code that can handle html anchor tags.  I need to test a string to see if it contains the '#'.  The code is returning URLs without '#' in them.

Thanks in advance
currTestIndex = currURL.find("#")
    if(currTestIndex == -1 or currTestIndex >= len(currURL)):
       print currURL
       return currURL

Open in new window

jonbergAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SuperdaveCommented:
Your code works for me.  Can you post a larger section of your program, or show an example that doesn't work?
0
jonbergAuthor Commented:
Sorry.  I switched to using the "re" library.  Maybe it wasn't working for me because I am using version 2.4.3 of Python.

Thanks though.
import re

rePound = re.compile("#")

if rePound.search(currURL) is not None:
   print currURL
   return currURL

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
peprCommented:
You may be interested in the standard module urlparse (http://docs.python.org/release/2.4.3/lib/module-urlparse.html; it was renamed/moved to urllib.parse in Python 3). Try the snippet below. It writes:

C:\tmp\___python\jonberg\Q_25855993>a.py
http
docs.python.org
/release/2.4.3/lib/module-urlparse.html
xyz
ParseResult(scheme='http', netloc='docs.python.org', path='/release/2.4.3/lib/module-urlparse.html', params='', query='', fragment='xyz')
('http', 'docs.python.org', '/release/2.4.3/lib/module-urlparse.html', '', '', 'xyz')
http://docs.python.org/release/2.4.3/lib/module-urlparse.html


import urlparse

url = 'http://docs.python.org/release/2.4.3/lib/module-urlparse.html#xyz'

x = urlparse.urlparse(url)

print x.scheme
print x.netloc
print x.path
print x.fragment
print 
print x

# The ParseResult class is actually derived from the tuple class.
print tuple(x)

# Construct the new URL from the parts.
nu = urlparse.urlunparse((x.scheme, x.netloc, x.path, '', '', ''))
print nu

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.