1.通过代码查看自己的ip
import random
import re
import time
from playwright.sync_api import sync_playwright # 导入playwright同步api
def 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地址如下图
文章来源:https://www.toymoban.com/news/detail-731899.html
2.加上隧道代理(以小象的隧道代理为例)
browser = playwright.chromium.launch(headless=False,
proxy={"server": "http://http-short.xiaoxiangdaili.com:10010",
"username": "xxxx",
"password": "xxxx"
})
输入服务器地址,用户名,密码即可
完整代码如下文章来源地址https://www.toymoban.com/news/detail-731899.html
import random
import re
import time
from playwright.sync_api import sync_playwright # 导入playwright同步api
def 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实例传入
到了这里,关于在playwright使用隧道代理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!