我有 PHP 代码,我正在调用 python 脚本,该脚本获取 URL,进入 Web URL,获取 JSON 页面,然后将 JSON 页面发送回 PHP 代码,但问题是我在数组中得到了 JSON 并且不是正确的 JSON 格式,有帮助吗?
蟒蛇代码:
import json
import sys
import bs4
import urllib.parse
link = urllib.parse.unquote(sys.argv[1])
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
context = browser.new_context(user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36')
page = context.new_page()
cookie_file = open('./cookies.json')
cookies = json.load(cookie_file)
context.add_cookies(cookies)
try:
page.goto(link)
page.wait_for_timeout(10000)
print(page.content())
page.close()
context.close()
browser.close()
except Exception as e:
print("Error in playwright script.")
page.close()
context.close()
browser.close()