Cookies and render for an angular js app using Phantomjs and python
Question: I have an object that can call a web page fine, even with `add_cookie`.
However, I want to render a site that is making heavy use of angularjs. For
some reason I seem to be unable to set the correct cookies, which I have
pulled from a live session. So I am uncertain how much of this is cookie-foo
that I'm getting wrong, and how much is angular-js-foo that needs to happen
that I'm missing. If people have input here that would be great, but even
comments pointing me to where to go ingest would be helpful because I'm not
getting far on my own. I've scrubbed the values following. Even some pointers
on how to debug this. My goal is to render the `div`s on the page.

    
    
    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    from bs4 import BeautifulSoup
    
    class WebPage():
    
        def __init__(self):
    
            dcap = dict(DesiredCapabilities.PHANTOMJS)
            dcap["phantomjs.page.settings.userAgent"] = (
                "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
                "(KHTML, like Gecko) Chrome/15.0.87"
            )
            self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
            self.driver.set_window_size(1024, 768)
    
        def get_page(self):
            url = "http://proadvisor.intuit.com/search/index-standalone.html?v2#/search-result?location=60613&distance=500"
            self.driver.get(url)
            cookie = {'aam_aud': 'a_value', 'ttax': 0}
            self.driver.add_cookie(cookie)
            page = BeautifulSoup(self.driver.page_source, "lxml")
            page.find_all("div")
    
    
    if __name__ == '__main__':
        wp = WebPage()
        wp.get_page()
    

and just now getting:

> selenium.common.exceptions.WebDriverException: Message: Error Message =>
> 'Can only set Cookies for the current domain' caused by Request =>
> {"headers":{"Accept":"application/json","Accept-
> Encoding":"identity","Connection":"close","Content-Length":"104","Content-
> Type":"application/json;charset=UTF-8","Host":"127.0.0.1:34940","User-
> Agent":"Python-
> urllib/3.3"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\":
> {\"aam_aud\": \"a_value\", \"ttax\": 0}, \"sessionId\":
> \"A-hash\"}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/a_hash/cookie"}


Answer: You have to add domain to your cookie.

Try something like this:

    
    
    cookie = {'aam_aud': 'a_value', 'ttax': 0, 'domain' : http://proadvisor.intuit.com}
    

You might have to play with it a bit for your base URL, but I think that
should work. You have to tell the cookie on what websites you want to use that
cookie on.

