Closed kennym closed 4 years ago
Hi, I believe 'url' should be 'project_url'
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'
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
)
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)
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.
@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?
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...
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:
This is the code:
What am I doing wrong?