Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python API调用接口 #31

Open
soyons opened this issue Jul 29, 2024 · 2 comments
Open

python API调用接口 #31

soyons opened this issue Jul 29, 2024 · 2 comments

Comments

@soyons
Copy link

soyons commented Jul 29, 2024

hello,可以出一个python的api接口吗,python传入一个指纹,直接打开对应环境的浏览器这种

@jindameias
Copy link

+1,手动太不方便了

@lightenthrive
Copy link

下面的代码,打不开页面,问题在哪里

import os
from playwright.sync_api import sync_playwright

# 需要先手动创建 worker-id 目录(已手动创建)
worker_id = 1

# VirtualBrowser 安装路径
virtual_browser_path = "C:/Program Files/VirtualBrowser/VirtualBrowser.exe"

# 启动浏览器的用户数据目录路径
user_data_dir = os.path.join(
    os.getenv("LOCALAPPDATA"), "VirtualBrowser", "Workers", str(worker_id)
)

with sync_playwright() as p:
    browser = p.chromium.launch_persistent_context(
        user_data_dir,
        executable_path=virtual_browser_path,  # 配置 VirtualBrowser 安装路径
        args=[f"--worker-id={worker_id}"],
        headless=False,  # 非无头模式
        viewport=None,  # 默认视图为全屏
    )

    # 打开新页面
    page = browser.new_page()
    page.goto("https://example.com")  # 替换为你的目标 URL

    # 在这里添加你的操作,例如截图或抓取内容
    print(page.title())

    # 关闭浏览器
    browser.close()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants