Note that there are some explanatory texts on larger screens.

plurals
  1. POAttributeError: based on re.compile pattern
    primarykey
    data
    text
    <p>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.</p> <p>I keep getting "elif conName.search(line): AttributeError: 'list' object has no attribute 'search'" on line 106</p> <p>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.</p> <p>When I comment out lines 105-123, the remainder of the code works finest kind.</p> <p>When I comment out lines 106-109, then lines 110-113 run fine, but I get the same error on line 114.</p> <pre><code>## This should be line 19 html_doc = """ &lt;title&gt;Flickr: username&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;meta property="og:title" content="username" /&gt; &lt;meta property="og:type" content="flickr_photos:profile" /&gt; &lt;meta property="og:url" content="http://www.flickr.com/people/Something/" /&gt; &lt;meta property="og:site_name" content="Flickr" /&gt; &lt;meta property="og:image" content="http://farm79.staticflickr.com/1111/buddyicons/99999999@N99.jpg?1234567890#99999999@N99" /&gt; &lt;li&gt; &lt;a href="/groups/theportraitgroup/"&gt;The Portrait Group&lt;/a&gt; &lt;span class="text-list-item"&gt; 1,939,830 photos,&amp;nbsp;125,874 members &lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="/groups/412762@N20/"&gt;Seagulls Gone Wild&lt;/a&gt; &lt;span class="text-list-item"&gt; 2,266 photos,&amp;nbsp;464 members &lt;/span&gt; &lt;/li&gt; """ 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("^.*/\"&gt;") # Group ID, could be ID or Href Href = re.compile("(\s)*&lt;a href=\"/groups/") # Strips to beginning of ID GName = re.compile("/\"&gt;(&lt;b&gt;)*") # Strips from end of Href to GName ## Persons contact info conName = re.compile("(\s)*&lt;meta property=\"og\:title\" content=\"") # Contact Name ##conName = re.compile("(\s)*&lt;a href=\"/groups/") conID = re.compile("(\s)*&lt;meta property=\"og\:image.*\#") # Gets conName's @N ID conRef = re.compile("(\s)*&lt;meta property=\"og\:url.*com/people/") Amp = re.compile("&amp;amp;") Qt = re.compile("&amp;quot;") Gt = re.compile("&amp;gt;") Lt = re.compile("&amp;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("/\"&gt;") 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, "&gt;", sLn) sLn = re.sub(Lt, "&lt;", sLn) sLn = re.sub(Qt, "\"", sLn) sLn = re.sub(Amp, "&amp;", sLn) OutFile.write(sLn) ## This should be line 104 ################################################# elif conName.search(line): ln = line ln = re.sub(conName, "", ln) conName = ln.split("\" /&gt;") elif conID.search(line) is not None: ln = line ln = re.sub(conID, "", ln) conID = ln.split("\" /&gt;") elif conRef.search(line) is not None: ln = line ln = re.sub(conRef, "", ln) conRef = ln.split("\" /&gt;") 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() </code></pre> <p>Does anyone have any ideas?</p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload