rajatomar788 / pywebcopy

Locally saves webpages to your hard disk with images, css, js & links as is.
https://rajatomar788.github.io/pywebcopy/
Other
527 stars 106 forks source link

setup_config() got an unexpected keyword argument 'url' #45

Closed kennym closed 4 years ago

kennym commented 4 years ago

Python version: 3.7.7

I'm using the same code as in the README, but I'm getting the following error when running it:

Traceback (most recent call last):
  File "main.py", line 14, in <module>
    pywebcopy.config.setup_config(**kwargs)
TypeError: setup_config() got an unexpected keyword argument 'url'

This is the code:

import pywebcopy

# Rest of the code is as usual
kwargs = {
    'url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}
pywebcopy.config.setup_config(**kwargs)
pywebcopy.save_webpage(**kwargs)

What am I doing wrong?

KuroiKuro commented 4 years ago

Hi, I believe 'url' should be 'project_url'

kennym commented 4 years ago

When I do that, I get:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    pywebcopy.save_webpage(**kwargs)
TypeError: save_webpage() missing 1 required positional argument: 'url'
rajatomar788 commented 4 years ago

Try it out simply as documented.

from pywebcopy import save_webpage

save_webpage(
 'http://example-site.com/',
 project_folder='path/to/downloads',
 project_name='xyz', 
 bypass_robots=True
)
dansaavedra commented 4 years ago

When I do that, I get:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    pywebcopy.save_webpage(**kwargs)
TypeError: save_webpage() missing 1 required positional argument: 'url'

I was able to get it to work by using project_url for setup_config and then changing it back to url for save_webpage. Something like this:

import pywebcopy

# Rest of the code is as usual
kwargs = {
    'project_url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}

kwargs2 = {
    'url': 'XXX',
    'project_folder': '/Users/kennymeyer/Projects/zyx',
    'project_name': 'zyx',
    'bypass_robots': True,
}
pywebcopy.config.setup_config(**kwargs)
pywebcopy.save_webpage(**kwargs2)
rajatomar788 commented 4 years ago

Ok cool. I still don't understand, why you can't keep it simple? But your implementation is ok too, so no worries.

from pywebcopy import save_webpage

save_webpage(
 'http://example-site.com/',
 project_folder='path/to/downloads',
 project_name='xyz', 
 bypass_robots=True
)

The function save_webpage automatically changes the global config and does the job without your need to manually configure it.

kennym commented 4 years ago

@rajatomar788 I need to set custom cookies. How would I do that with your approach? Also, can you fix your README example and/or fix the API?

rajatomar788 commented 4 years ago

If you need to set cookies then just import the SESSION variable from pywebcopy then configure it and continue as above.

import requests 
from pywebcopy import SESSION

cookie_obj = requests.cookies.create_cookie(domain='www.domain.com',name='COOKIE_NAME',value='the cookie works')
SESSION.cookies.set_cookie(cookie_obj)

# rest of the code as above...