Created
June 10, 2024 21:43
-
-
Save douglasmiranda/ee275709d479460832c06d563b326d47 to your computer and use it in GitHub Desktop.
Testing browserless deployed on Google Cloud Run + Google API Gateway
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# API GATEWAY URL | |
browserless_url = "https://..../config" | |
url = "https://example.com/" | |
# token: BROWSERLESS TOKEN | |
querystring = {"token":"XYZ", "timeout":"1200000"} | |
response = requests.get( | |
browserless_url, | |
headers={"x-api-key": "API GATEWAY API KEY"}, | |
params=querystring | |
) | |
print(response.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
browserless_url = "https://..../chrome/function" | |
url = "https://example.com/" | |
querystring = {"token":"XYZ", "timeout":"1200000"} | |
payload = """ | |
export default async function ({ page }) { | |
await page.goto("%s", {waitUntil: 'networkidle2', timeout: 1200000}); | |
const element = await page.waitForSelector('h1'); | |
const h1_value = await element.evaluate(el => { | |
return el.innerText; | |
}); | |
return { | |
data: { | |
h1_value: h1_value, | |
}, | |
type: "application/json", | |
}; | |
} | |
""" % url | |
response = requests.post(browserless_url, json={"code": payload}, headers={"x-api-key": "API GATEWAY API KEY"}, params=querystring) | |
print(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment