0

I have working with Python and I have some questions:

  1. I am using BeautifulSoup I want to replace an HTML tag with another one.

Here is code example:

html = BeautifulSoup(p)
            x = html.find('a', attrs={'href':'/slideshow'})

            while x:
                print 'x unchanged - ', x
                x=x.replaceWith('<a href="/slideshow_v2">')
                print 'x changed - ', x

Thanks for help !!!

1 Answer 1

1

here is a solution to your problem:

html = BeautifulSoup(p)
anchors = html.findAll('a', href='/slideshow')

for anchor in anchors:
    anchor['href'] = '/slideshow_v2'

print html.findAll('a', href='/slideshow_v2')

Take into acount please that this is not a Django related question.

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.