Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:48:56+00:00 2026-06-16T01:48:56+00:00

I am trying to parse a website and retrieve the texts that contain Hyper

  • 0

I am trying to parse a website and retrieve the texts that contain Hyper link.
For eg:

<a href="www.example.com">This is an Example</a>

I need to retrieve “This is an Example”, which I am able to do for pages that dont have broken tags. I am unable to retrieve in following case:

<html>
<body>
<a href = "http:\\www.google.com">Google<br>
<a href = "http:\\www.example.com">Example</a>
</body>
</html>

In such cases it the code is unable to retrieve Google because of the broken tag that links google and only gives me “Example”. Is there a way to also retrieve “Google”?

My code is here:

from bs4 import BeautifulSoup
from bs4 import SoupStrainer

f = open("sol.html","r")

soup = BeautifulSoup(f,parse_only=SoupStrainer('a'))
for link in soup.findAll('a',text=True):
    print link.renderContents();

Please note sol.html contains the above given html code itself.

Thanks
– AJ

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:48:57+00:00Added an answer on June 16, 2026 at 1:48 am

    Remove text=True from your code and it should work just fine:

    >>> from bs4 import BeautifulSoup
    >>> soup = BeautifulSoup('''
    ... <html>
    ... <body>
    ... <a href = "http:\\www.google.com">Google<br>
    ... <a href = "http:\\www.example.com">Example</a>
    ... </body>
    ... </html>
    ... ''')
    >>> [a.get_text().strip() for a in soup.find_all('a')]
    [u'Google', u'Example']
    >>> [a.get_text().strip() for a in soup.find_all('a', text=True)]
    [u'Example']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse a website that searches by content1 or content2 depending
I'm trying to retrieve articles through wikipedia API using this code $url = 'http://en.wikipedia.org/w/api.php?action=parse&page=example&format=json&prop=text';
I'm trying to parse some data out of a website. The problem is that
So I am trying to develop a program that will parse a website for
So I'm trying to parse from this website http://dl.acm.org/dl.cfm . This website doesn't allow
I am trying to parse one element from a website that is inside of
Im trying to parse a website using the Mechanize Gem. So far this is
I'm trying to parse a title from the following piece of html: Website (Newton)
I'm trying to use JSoup in my android app to parse a certain website.
Trying to parse some XML but apparently this is too much for a lazy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.