1.通过代码查看自己的ip import randomimport reimport timefrom playwright.sync_api import sync_playwright # 导入
import randomimport reimport timefrom playwright.sync_api import sync_playwright # 导入playwright同步apidef run(playwright): # 定义run方法 browser = playwright.chromium.launch(headless=False) context = browser.new_context() # 创建context对象,context之间是相互隔离的,可以理解为轻量级的浏览器实例 page = context.new_page() # 创建page对象,真正打开浏览器界面 url = "Http://httpbin.org/ip" page.Goto(url, timeout=120000) time.sleep(6) for i in range(1,10): # input("输入continue") print("***",page.content()) time.sleep(10) page.goto(url, timeout=120000) # page.reload(timeout=120000)if __name__ == '__main__': with sync_playwright() as playwright: # playwright使用入口,通过上下文方式 run(playwright) # 调用run方法,将playwright实例传入
通过以上方法可以看到自己的ip地址如下图
browser = playwright.chromium.launch(headless=False, proxy={"server": "http://http-short.xiaoxiangdaili.com:10010", "username": "xxxx", "passWord": "xxxx" })
输入服务器地址,用户名,密码即可
完整代码如下
import randomimport reimport timefrom playwright.sync_api import sync_playwright # 导入playwright同步apidef run(playwright): # 定义run方法 browser = playwright.chromium.launch(headless=False, proxy={"server": "http://http-short.xiaoxiangdaili.com:10010", "username": "xxxx", "password": "xxxx" }) # chromium的browser对象,当前使用的是playwright安装的自带的chromium context = browser.new_context() # 创建context对象,context之间是相互隔离的,可以理解为轻量级的浏览器实例 page = context.new_page() # 创建page对象,真正打开浏览器界面 url = "http://httpbin.org/ip" page.goto(url, timeout=120000) time.sleep(6) for i in range(1,10): # input("输入continue") print("***",page.content()) time.sleep(10) page.goto(url, timeout=120000)if __name__ == '__main__': with sync_playwright() as playwright: # playwright使用入口,通过上下文方式 run(playwright) # 调用run方法,将playwright实例传入
来源地址:https://blog.csdn.net/Awesome_py/article/details/129861755
--结束END--
本文标题: 在playwright使用隧道代理
本文链接: https://lsjlt.com/news/412072.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0