Python Forum
urlparse to urllib.parse - the script stopped working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
urlparse to urllib.parse - the script stopped working
#1
dear community


The following code runned - like a charme - all is nice. Very well. in python version 2.xy


import urllib
import urlparse
import re

url = "http://search.cpan.org/author/?W"
html = urllib.urlopen(url).read()
for lk, capname, name in re.findall('<a href="(/~.*?/)"><b>(.*?)</b></
a><br/><small>(.*?)</small>', html):
    alk = urlparse.urljoin(url, lk)

    data = { 'url':alk, 'name':name, 'cname':capname }

    phtml = urllib.urlopen(alk).read()
    memail = re.search('<a href="mailto:(.*?)">', phtml)
    if memail:
        data['email'] = memail.group(1)

    print data
i got back the following


    
    IndentationError: Missing parentheses in call to 'print'
>>> 
>>> import urllib
>>> import urllib.parse
>>> import re
>>> 
>>> url = "http://search.cpan.org/author/?W"
>>> html = urllib.urlopen(url).read()
Traceback (innermost last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'urlopen'
>>> for lk, capname, name in re.findall('<a href="(/~.*?/)"><b>(.*?)</b></
  File "<stdin>", line 1
    for lk, capname, name in re.findall('<a href="(/~.*?/)"><b>(.*?)</b></
                                                                         ^
SyntaxError: EOL while scanning string literal
>>> a><br/><small>(.*?)</small>', html):
  File "<stdin>", line 1
    a><br/><small>(.*?)</small>', html):
      ^
SyntaxError: invalid syntax
>>>     alk = urlparse.urljoin(url, lk)
  File "<stdin>", line 1
    alk = urlparse.urljoin(url, lk)
    ^
IndentationError: unexpected indent
>>> 
>>>     data = { 'url':alk, 'name':name, 'cname':capname }
  File "<stdin>", line 1
    data = { 'url':alk, 'name':name, 'cname':capname }
    ^
IndentationError: unexpected indent
>>> 
>>>     phtml = urllib.urlopen(alk).read()
  File "<stdin>", line 1
    phtml = urllib.urlopen(alk).read()
    ^
IndentationError: unexpected indent
>>>     memail = re.search('<a href="mailto:(.*?)">', phtml)
  File "<stdin>", line 1
    memail = re.search('<a href="mailto:(.*?)">', phtml)
    ^
IndentationError: unexpected indent
>>>     if memail:
  File "<stdin>", line 1
    if memail:
    ^
IndentationError: unexpected indent
>>>         data['email'] = memail.group(1)
  File "<stdin>", line 1
    data['email'] = memail.group(1)
    ^
IndentationError: unexpected indent
>>> 
>>>     print data
  File "<stdin>", line 1
    print data
    ^
IndentationError: Missing parentheses in call to 'print'
>>> 
okay - first of all i have to install the urllib.parse module
but i guess that there are some other errors waiting at the fence ...
Reply


Messages In This Thread
urlparse to urllib.parse - the script stopped working - by apollo - Oct-24-2017, 08:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  urllib can't find "parse" rjdegraff42 6 2,224 Jul-24-2023, 05:28 PM
Last Post: deanhystad
  Help with urllib.request Brian177 2 2,887 Apr-21-2021, 01:58 PM
Last Post: Brian177
  Spyder stopped working in Windows 10 gammaray 3 3,094 Apr-19-2021, 05:33 PM
Last Post: jefsummers
  urllib.request ericmt123 2 2,457 Dec-21-2020, 06:53 PM
Last Post: Larz60+
  urllib is not a package traceback cc26 3 5,428 Aug-28-2020, 09:34 AM
Last Post: snippsat
  for loop script over telnet in Python 3.5 is not working abhijithd123 1 2,910 May-10-2020, 03:22 AM
Last Post: bowlofred
  countdown script not working..plz help what is mistake randyjack 1 2,123 Oct-28-2019, 06:57 AM
Last Post: perfringo
  picamera not working on premade script georgeaura 1 2,537 Jul-24-2019, 10:11 AM
Last Post: gontajones
  urllib request error 404 Coco 2 4,422 May-11-2019, 02:47 PM
Last Post: Larz60+
  python has stopped working sally 1 6,031 Nov-22-2018, 10:19 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020