在playwright使用隧道代理
短信预约 -IT技能 免费直播动态提醒
1.通过代码查看自己的ip
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地址如下图
2.加上隧道代理(以小象的隧道代理为例)
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
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341