0

I get a generator object error instead of the css URLs I am trying to extract. Can someone help resolve?

>>> import cssutils
>>> cssutils.getUrls('http://4nprofessionals.com/css/style.css')
    <generator object getUrls at 0x000001647F5FC0A0>
>>> css = cssutils.getUrls('http://4nprofessionals.com/css/style.css')
>>> print (css)
    <generator object getUrls at 0x000001647F6B4BF8>
DYZ
  • 55,249
  • 10
  • 64
  • 93
devmaster2
  • 47
  • 1
  • 5
  • The simplest solution is to convert it to a list with `list()`. A better solution is to read about generators and how to use them. – DYZ Feb 09 '17 at 21:51
  • 3
    Possible duplicate of [What can you use Python generator functions for?](http://stackoverflow.com/questions/102535/what-can-you-use-python-generator-functions-for) – DYZ Feb 09 '17 at 21:52
  • Thanks. I tried converting to a list and got the following errors:>>> list(css) Traceback (most recent call last): File "", line 1, in list(css) File "C:\AppData\Local\Programs\Python\Python36\lib\site-packages\cssutils\__init__.py", line 211, in getUrls for importrule in (r for r in sheet if r.type == r.IMPORT_RULE): File "C:\AppData\Local\Programs\Python\Python36\lib\site-packages\cssutils\__init__.py", line 211, in for importrule in (r for r in sheet if r.type == r.IMPORT_RULE): AttributeError: 'str' object has no attribute 'type' – devmaster2 Feb 09 '17 at 22:25
  • This must be an issue with `cssutils`. – DYZ Feb 09 '17 at 22:35
  • the issue is in line 211 in ini.py inside the cssutils folder: File "C:\AppData\Local\Programs\Python\Python36\lib\site-packages‌​\cssutils_init_.py", line 211, in getUrls for importrule in (r for r in sheet if r.type == r.IMPORT_RULE): File "C:\\AppData\Local\Programs\Python\Python36\lib\site-package‌​s\cssutils_init_.py"‌​, line 211, in for importrule in (r for r in sheet if r.type == r.IMPORT_RULE): AttributeError: 'str' object has no attribute 'type' any thoughts? – devmaster2 Feb 10 '17 at 01:02

0 Answers0