gazpacho icon indicating copy to clipboard operation
gazpacho copied to clipboard

AttributeError: 'Soup' object has no attribute 'decode'

Open js-compilatrum opened this issue 3 years ago • 2 comments

I tried code:

all_urls = [link.attrs['href'] for link in Soup(get(browser_link)).find('a')]

and I got AttributeError: 'Soup' object has no attribute 'decode'. What check? Where is mistake in my code?

Full info:

File "C:\webscraper\lib\site-packages\gazpacho\get.py", line 29, in get
    url = sanitize(url)
  File "C:\webscraper\lib\site-packages\gazpacho\utils.py", line 128, in sanitize
    scheme, netloc, path, query, fragment = urlsplit(url)
  File "C:\Program Files\Python39\lib\urllib\parse.py", line 455, in urlsplit
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "C:\Program Files\Python39\lib\urllib\parse.py", line 125, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "C:\Program Files\Python39\lib\urllib\parse.py", line 109, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'Soup' object has no attribute 'decode'

js-compilatrum avatar Jan 15 '21 22:01 js-compilatrum

Seems it’s failing on get...

I would replace get with requests.get, and then use Soup() on the resulting html.

maxhumber avatar Jan 16 '21 16:01 maxhumber

I tried in production and your recommendation is the best one. Problem was solved this way. Thank you

js-compilatrum avatar Jan 30 '21 15:01 js-compilatrum