I am trying to graph cookies from Facebook. My intension is to using selenium for web automation. I am using pickle to grab cookies.
Code:
import pickle
from selenium import webdriver
driver = webdriver.Chrome("../chromedriver.exe")
def save_cookies(driver, location):
pickle.dump(driver.get_cookies(), open(location, "wb"))
cookies_location = "C:\Users\User\PycharmProjects\Campaign\Experiments\cookies.txt"
# Initial load of the domain that we want to save cookies for
chrome = driver
chrome.get("https://www.facebook.com/")
username = os.environ.get('facebook_zrliqi_email')
password = os.environ.get('facebook_zrliqi_pass')
driver.find_element_by_name("email").send_keys(username)
driver.find_element_by_name("pass").send_keys(password)
driver.find_element_by_name("login").click()
print(input("Press any Key: "))
print("Login work Successfully ")
save_cookies(chrome, cookies_location)
chrome.quit()
But when I try to pip install pickle in my Pycharm. I am fetching it needs to install visual studio tools.
I got this error:
building 'pickle5._pickle' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
Disclaimer : I extracted this answer from the OPs question. Answers should not be contained in the question itself .
You don't have to install pickle. Pickle is already in the python standard library. when I was working on that I learnt that. And thanks to @tdelaney for let me know it's a part of python standard library.
base on that error:
"C:\Users\User\PycharmProjects\Campaign\Experiments\Cookies.py", line 47 cookies_location = "C:\Users\User\PycharmProjects\Campaign\Experiments\cookies.txt" ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
you have a Unicode problem.
cookies_location = r"C:\Users\User\PycharmProjects\Campaign\Experiments\cookies.txt
putting r before your string solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.