S
S
Slava00722019-10-31 05:37:08
Python
Slava0072, 2019-10-31 05:37:08

How to fix AttributeError: 'TorBrowserDriver' object has no attribute 'add_cookies'?

I used tbselenium library with this code.

from argparse import ArgumentParser
from tbselenium.tbdriver import TorBrowserDriver


def print_cookies(tbb_dir, url):
    with TorBrowserDriver(tbb_dir) as driver:
        driver.load_url(url)
        print ("Finished loading", url)
        print ("Cookies:", driver.execute_script("return document.cookie;"))
        driver.add_cookies({})    


def mainn():
    desc = "Print cookies on a given URL"
    nyt_hs_url = "https://www.nytimes3xbfgragh.onion/"  # NYT Hidden Service
    parser = ArgumentParser(description=desc)
    parser.add_argument('tbb_path')
    parser.add_argument('url', default=nyt_hs_url)
    args = parser.parse_args()
    print_cookies(args.tbb_path, args.url)

mainn()

But it throws an error : "AttributeError: 'TorBrowserDriver' object has no attribute 'add_cookies'"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Dugin, 2019-10-31
@adugin

Stop programming in notepad and learn how to use one of the IDEs.
Then you will not have problems a la "how to see what methods an object has."

G
Garry_Galler, 2019-10-31
@Garry_Galler

The driver object does not have an add_cookies method.
There is an add_cookie method.
As written above, this is easy to check in the IDE.
And learn to use the documentation.
PS By the way, main is written with one n.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question