当前位置:网站首页>浏览器cookie转selenium cookie登录
浏览器cookie转selenium cookie登录
2022-06-27 12:01:00 【於 兔シ】
python使用selenium模拟操作Chrome浏览器,cookie的添加
webdriver下载
chrome浏览器驱动
http://chromedriver.storage.googleapis.com/index.html
找到对应驱动并下载。
准备好cookie
我是从浏览器去拿的如图:
import time
from selenium import webdriver
cookie = 'uuid_tt_dd=10_19093309300-1614257743141-276654; UN=yutu75; Hm_ct_6bcd52f51e9b3dce32bec4a3997715ac=6525*1*10_19093309300-1614257743141-276654!5744*1*yutu75; _ga=GA1.2.663410303.1614267961; __gads=ID=95dd03f56e1370d0-22571a531fca005d:T=1625409214:RT=1625409214:S=ALNI_MY-aWM9Zr2zrKvEuliojR5MyBUkvg; UserName=yutu75; UserInfo=9eeb838640814c459d2eb06c2429558f; UserToksssssue%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isonline%22%3A%7B%22value%22%3A%221%22%2C%22scope%22%3A1%7D%2C%22isvip%22%3A%7B%22value%22%3A%220%22%2C%22scope%22%3A1%7D%2C%22uid_%22%3A%7B%22value%22%3A%22yutu75%22%2C%22scope%22%3A1%7D%7D; Hm_lvt_e5ef47b9f471504959267fd614d579cd=1650853482,1653295631; management_ques=1653996231708; c_dl_prid=1654683664939_325152; c_dl_rid=1654781258952_148261; c_dl_fref=https://www.baidu.com/link; c_dl_fpage=/download/weixin_42098251/18445929; c_dl_um=-; historyList-new=%5B%22%E5%B0%8F%E7%B1%B3%E6%89%8B%E6%9C%BA%E5%88%B7%E9%B8%BF%E8%92%99%E7%B3%BB%E7%BB%9F%22%5D; FCNEC=[["AKsRol_6zPNvPIPgBuo9ajx1VkA0uJY4Cw-C2xSpr7-tCPqfuVbUKo1VrlCXXMP84-3sXal_NRQ1yN2uM7n1aNiPiyLPd9ccSd-id4OqQfGL8kiEIM5TIo-o1UcZ7r0tL0oE-cvAmFYB-jMclYhtemkQ8GcBanOfUg=="],null,[]]; dc_session_id=10_1655985521086.882045; firstDie=1; __gpi=UID=0000050dec0d6a33:T=1651075728:RT=1655985931:S=ALNI_MYRr0bDHGBvHVc2YzfX6gM9FFjNuA; dc_sid=9a353d315b813af0fdbfdade80aea75c; c_segment=14; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1655801615,1655887598,1655985522,1655986686; c_first_ref=default; c_first_page=https%3A//mp.csdn.net/%3Fspm%3D1010.2135.3001.4503; c_dsid=11_1655989376923.788455; c_page_id=default; c_pref=https%3A//mp.csdn.net/mp_blog/manage/article%3Fspm%3D1003.2000.3001.5448; c_ref=https%3A//mp.csdn.net/mp_blog/manage/article%3Fspm%3D1011.2415.3001.5448; dc_tos=rdxm31; log_Id_pv=1013; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1655990030; log_Id_view=3024; log_Id_click=553'
url = f'https://blog.csdn.net/nav/python'
webdriver_path = r'C:\Users\xiao3\Desktop\selenium\chromedriver.exe'
def get_cookie_list():
""" :param : 从浏览器cv的或者去从requests里获取到的cookie :return: 反回cookie列表 """
cookie_list = []
for i in cookie.split(';'):
i_dict = {
'name': i.split('=')[0].strip(), 'value': i.split('=')[1].strip()}
cookie_list.append(i_dict)
return cookie_list
def main():
try:
driver = webdriver.Chrome(webdriver_path)
driver.get(url)
time.sleep(1)
cookie_list = get_cookie_list()
for c_i in cookie_list:
driver.add_cookie(c_i)
time.sleep(1)
driver.get(url)
time.sleep(5)
driver.close()
driver.quit()
except Exception as e:
print(e)
driver.quit()
if __name__ == '__main__':
main()
结果图:
边栏推荐
- .NET6接入Skywalking链路追踪完整流程
- The DBSCAN function of FPC package in R language performs density clustering analysis on data, and the plot function visualizes the clustering graph
- Jwas: a Bayesian based GWAS and GS software developed by Julia
- Jianmu continuous integration platform v2.5.0 release
- Unlock the secret of C language key words (issue 6)
- MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
- Mybaitis generator details
- 56. Core principle of flutter - flutter startup process and rendering pipeline
- [on Nacos] get started quickly
- yml的配置
猜你喜欢

巅峰小店APP仿站开发玩法模式讲解源码分享

Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022

微服务拆分

In 2021, the global carbon graphite brush revenue is about US $2366million, and it is expected to reach US $2701.8 million in 2028

动态规划【四】(计数类dp)例题:整数划分

私藏干货分享:关于企业架构中如何进行平台化

In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
![Dynamic programming [4] (counting class DP) example: integer partition](/img/06/4b3863bbb85582348c6f4ea7c5511e.png)
Dynamic programming [4] (counting class DP) example: integer partition

Drive to APasS! Use Mingdao cloud to manage F1 events

MapReduce原理剖析(深入源码)
随机推荐
What's the matter with Amazon's evaluation dropping and failing to stay? How to deal with it?
MapReduce principle analysis (in-depth source code)
C# wpf 实现撤销重做功能
数学知识——博弈论(巴什博奕、尼姆博奕、威佐夫博奕)思路及例题
Mathematical knowledge -- ideas and examples of game theory (bash game, Nim game, wizov game)
master公式
如何修改 node_modules 裏的文件
亚马逊测评掉评、留不上评是怎么回事呢?要如何应对?
The GLM function of R language is used to build a binary logistic regression model (the family parameter is binomial), and the AIC function is used to compare the AIC values of the two models (simple
How histrix works
Wechat applet realizes five-star evaluation
c/s 架构
In 2021, the global professional liability insurance revenue was about USD 44740million, and it is expected to reach USD 55980million in 2028. From 2022 to 2028, the CAGR was 3.5%
Topic37——64. 最小路径和
StarCraft's Bug King ia retired for 2 years to engage in AI, and lamented that it was inferior
This privatized deployed enterprise knowledge base makes telecommuting a zero distance
MySQL高阶语句(一)
Microservice splitting
The DBSCAN function of FPC package in R language performs density clustering analysis on data, and the plot function visualizes the clustering graph
Wechat applet payment password input