Commit
·
e264582
1
Parent(s):
050c5eb
Added middleware
Browse files- test2.py +14 -0
- webrify2.py +31 -0
test2.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
url = "https://webrify1.p.rapidapi.com/seo"
|
4 |
+
|
5 |
+
querystring = {"url":"https://www.benchify.com"}
|
6 |
+
|
7 |
+
headers = {
|
8 |
+
"x-rapidapi-key": "cdb687459dmsh984de56912ae924p173d7fjsn78d4034f938d",
|
9 |
+
"x-rapidapi-host": "webrify1.p.rapidapi.com"
|
10 |
+
}
|
11 |
+
|
12 |
+
response = requests.get(url, headers=headers, params=querystring)
|
13 |
+
|
14 |
+
print(response.json())
|
webrify2.py
CHANGED
@@ -176,10 +176,41 @@ async def get_metadata(url: str):
|
|
176 |
await pw.stop()
|
177 |
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
@app.get("/screenshot", response_model=ScreenshotResponse)
|
180 |
async def get_screenshot(url: str):
|
181 |
page, browser, pw = await get_page(url)
|
182 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
image_bytes = await page.screenshot(full_page=True)
|
184 |
image_base64 = base64.b64encode(image_bytes).decode()
|
185 |
return {"screenshot": image_base64}
|
|
|
176 |
await pw.stop()
|
177 |
|
178 |
|
179 |
+
# @app.get("/screenshot", response_model=ScreenshotResponse)
|
180 |
+
# async def get_screenshot(url: str):
|
181 |
+
# page, browser, pw = await get_page(url)
|
182 |
+
# try:
|
183 |
+
# image_bytes = await page.screenshot(full_page=True)
|
184 |
+
# image_base64 = base64.b64encode(image_bytes).decode()
|
185 |
+
# return {"screenshot": image_base64}
|
186 |
+
# finally:
|
187 |
+
# await browser.close()
|
188 |
+
# await pw.stop()
|
189 |
@app.get("/screenshot", response_model=ScreenshotResponse)
|
190 |
async def get_screenshot(url: str):
|
191 |
page, browser, pw = await get_page(url)
|
192 |
try:
|
193 |
+
# Scroll to bottom to trigger lazy-loaded content
|
194 |
+
await page.evaluate("""
|
195 |
+
() => {
|
196 |
+
return new Promise((resolve) => {
|
197 |
+
let totalHeight = 0;
|
198 |
+
const distance = 100;
|
199 |
+
const timer = setInterval(() => {
|
200 |
+
window.scrollBy(0, distance);
|
201 |
+
totalHeight += distance;
|
202 |
+
if (totalHeight >= document.body.scrollHeight) {
|
203 |
+
clearInterval(timer);
|
204 |
+
resolve();
|
205 |
+
}
|
206 |
+
}, 100);
|
207 |
+
});
|
208 |
+
}
|
209 |
+
""")
|
210 |
+
|
211 |
+
# Give time for images and content to load
|
212 |
+
await page.wait_for_timeout(2000)
|
213 |
+
|
214 |
image_bytes = await page.screenshot(full_page=True)
|
215 |
image_base64 = base64.b64encode(image_bytes).decode()
|
216 |
return {"screenshot": image_base64}
|