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

  • SEARCH
  • Home
  • 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 8971479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:58:00+00:00 2026-06-15T17:58:00+00:00

I’m new at Python, and I’m pretty sure that the cause of this is

  • 0

I’m new at Python, and I’m pretty sure that the cause of this is simply a blonde moment, but it’s been driving me up the wall the past few days.

I keep getting “elif conName.search(line): AttributeError: ‘list’ object has no attribute ‘search'” on line 106

If I replace the pattern in line 54 with the one from line 50, then lines 106-113 run fine, but I get the same error on line 114.

When I comment out lines 105-123, the remainder of the code works finest kind.

When I comment out lines 106-109, then lines 110-113 run fine, but I get the same error on line 114.

##  This should be line 19
html_doc = """
        <title>Flickr: username</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta property="og:title" content="username" />
        <meta property="og:type" content="flickr_photos:profile" />
        <meta property="og:url" content="http://www.flickr.com/people/Something/" />
        <meta property="og:site_name" content="Flickr" />
        <meta property="og:image" content="http://farm79.staticflickr.com/1111/buddyicons/99999999@N99.jpg?1234567890#99999999@N99" />

                <li>
                <a href="/groups/theportraitgroup/">The Portrait Group</a>
                <span class="text-list-item">
        1,939,830 photos,&nbsp;125,874 members    
                </span>
        </li>
                <li>
                <a href="/groups/412762@N20/">Seagulls Gone Wild</a>
                        <span class="text-list-item">
                2,266 photos,&nbsp;464 members
                </span>
                                                        </li> """

from urllib.request import urlopen
from bs4 import BeautifulSoup
import fileinput
import re
                                ##  This should be line 46
## Strips for basic group data
Tab      = re.compile("(\t){1,}")                                                    # strip tabs
ID       = re.compile("^.*/\">")                                    # Group ID, could be ID or Href
Href     = re.compile("(\s)*<a href=\"/groups/") # Strips to beginning of ID
GName    = re.compile("/\">(<b>)*")                                    # Strips from end of Href to GName

## Persons contact info
conName  = re.compile("(\s)*<meta property=\"og\:title\" content=\"")        # Contact Name 
##conName = re.compile("(\s)*<a href=\"/groups/")
conID    = re.compile("(\s)*<meta property=\"og\:image.*\#")                    # Gets conName's @N ID
conRef   = re.compile("(\s)*<meta property=\"og\:url.*com/people/")

Amp   = re.compile("&amp;")
Qt    = re.compile("&quot;")                                                
Gt    = re.compile("&gt;")
Lt    = re.compile("&lt;")


exfile = 1        ## 0 = use internal data, 1 = use external file

InFile = html_doc

if exfile:
        InFile = open('\Python\test\Group\group 50 min.ttxt', 'r', encoding = "utf-8", errors = "backslashreplace")
        closein = 1        ## Only close input file if it was opened
else:
        closein = 0

OutFile = open('C:\Python\test\Group\Output.ttxt', 'w', encoding = "utf-8", errors = "backslashreplace")
cOutFile = open('C:\Python\test\Group\ContactOutput.ttxt', 'w', encoding = "utf-8", errors = "backslashreplace")

i = 1    ## counter for debugging

                                ##  This should be line 80
for line in InFile:
##    print('{}'.format(i), end = ', ') ## this is just a debugging line, to see where the program errors out
##    i += 1
        if Href.search(line):
                ln = line
                ln = re.sub(Href, "", ln)
                gID, Name = ln.split("/\">")
                Name = Name[:-5]    ## this removes the "\n" at EOL as well
                if "@N" in gID:
                        rH = ""
                else:        
                        rH = gID
                        gID = ""

##        sLn = '{3}\t{0}\t{1}\t{2}\n'.format(Name, gID, rH, conName)
                sLn = '{0}\t{1}\t{2}\n'.format(Name, gID, rH, conName)
                        ##  Replace HTML codes
                sLn = re.sub(Gt, ">", sLn)
                sLn = re.sub(Lt, "<", sLn)
                sLn = re.sub(Qt, "\"", sLn)
                sLn = re.sub(Amp, "&", sLn)

                OutFile.write(sLn)
                        ##  This should be line 104
                #################################################    
        elif conName.search(line):
                ln = line
                ln = re.sub(conName, "", ln)
                conName = ln.split("\" />")
        elif conID.search(line) is not None:
                ln = line
                ln = re.sub(conID, "", ln)
                conID = ln.split("\" />")
        elif conRef.search(line) is not None:
                ln = line
                ln = re.sub(conRef, "", ln)
                conRef = ln.split("\" />")
        else:
                pass

        sLn = '{0}\t{1}\t{2}\n'.format(conID, conRef, conName)
        cOutFile.write(sLn)        ## I know, this will make a massive file with duplicated data, but deal w/ it later
                #################################################

if closein:
        InFile.close()
OutFile.close()
cOutFile.close()

Does anyone have any ideas?

Thank you!

  • 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-15T17:58:02+00:00Added an answer on June 15, 2026 at 5:58 pm

    I keep getting “elif conName.search(line): AttributeError: ‘list’ object has no attribute ‘search'” on line 106

    It means that conName is a list at this moment. And indeed 2 lines below you assign conName to a list:

    conName = ln.split("\" />")
    

    After the first conName.search() returned a successful match you changed it to a list so for the following lines from the file (the next loop iterations) conName.search produces the error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.