问题遇到的现象和发生背景
from ichrome import AsyncChromeDaemon
用代码块功能插入代码,请勿粘贴截图
import random
import asyncio
from ichrome import AsyncChromeDaemon
from newLiveInfo.getProxy import getProxy
async def startup_chrome(dp_port=random.randint(1000,10000)):
"""
设置 chrome 参数,然后启动 chrome
:param dp_port: 自定义 debug port
:return:
"""
proxyinfo = getProxy('redis')
proxies = f"{proxyinfo['host']}:{proxyinfo['port']}"
async with AsyncChromeDaemon(port=dp_port,proxy = proxies, headless=False) as cd:
async with cd.connect_tab(index=0) as tab:
url = 'http://www.baidu.com' #根据需要填写
await tab.set_url(url, timeout=5)
await asyncio.sleep(30)
title = await tab.title
if "滑动验证页面" in title:
aaa = await tab.get_element_clip('#nc_1__scale_text > span')
start_x = aaa['x']
start_y = aaa['y']
# 滑动滑块
await tab.mouse_drag_rel_chain(start_x, start_y).move(300, 0, 1)
await asyncio.sleep(10)
# 获取cookie
cookie_list = await tab.get_cookies(url, timeout=5)
cookie = ';'.join([f"{i.get('name')}={i.get('value')}" for i in cookie_list])
return cookie
if __name__ == "__main__":
cookie = asyncio.run(startup_chrome())
print(cookie)
'http://账号:密码@111.225.152.200:51756'
这种会提示断开链接
运行结果及报错内容
挂代理需要验证账号密码
我想要达到的结果
可以用代理,不需要手动填写账号密码。