'Python requests_html sleep to render Dynamic HTML
I'm trying to use requests_html to wait 16 seconds before the js on an HTML page renders dynamic HTML. Can you help me? ss.contents is returning empty but I can print hardcoded HTML from the #spellbook div.
import keyboard
from requests_html import HTMLSession
from bs4 import BeautifulSoup
url = 'https://dubioustunic.github.io/spinning-sword/philosophersstone'
s = HTMLSession()
response = s.get(url)
response.html.render(sleep = 16)
soup = BeautifulSoup(response.content, 'html.parser')
ss = soup.find("div", {"id": "spellbook"})
keyboard.write(ss.contents[0])
edit: don't tell me to use selenium it's not working b/c of remnants of Bill Gates' old Monopoly
Solution 1:[1]
I did it myself I used Playwright.
Full code:
import time
import sys
import pyautogui
import keyboard
from requests_html import HTMLSession
import asyncio
import pyppeteer
from promise import Promise
from bs4 import BeautifulSoup
# ?????HTMLSession?
# HTMLSession??????pyppeteer?,????????pyppeteer??
import asyncio
from playwright.async_api import async_playwright
#Hall the horizon, whilst he saileth, saileth towards the "east side of heaven, his #sister figure of Mut painted upon a piece of linen, and over the figures of two import asyncio from playwright.async_api import async_playwright
count = 0;
while(True):
count += 1;
print(count);
pyautogui.click(201, 555)
async def run(playwright):
chromium = playwright.chromium
browser = await chromium.launch()
page = await browser.new_page()
for current_url in ["https://dubioustunic.github.io/spinning-sword/philosophers_stone"]:
await page.goto(current_url, wait_until="domcontentloaded")
element = await page.wait_for_selector("#spellbook")
keyboard.write(await element.inner_text())
await browser.close()
#IN ALL THE EARTH . CHAPTER CLXIV. [From Lepsius, Todtenbnch, Bl . 78.] Vignette #: A goddess, to the West, stretch "out thy hand to Teta,
async def main():
async with async_playwright() as playwright:
await run(playwright)
asyncio.run(main())
#session = HTMLSession2()
#session.browser
#response = session.get(url=url)
#response.html.render(sleep = 66)#OPTIMUS PRIME
#soup = BeautifulSoup(response.content, 'html.parser')
#ss = soup.find("div", {"id": "spellbook"})
#print(ss.contents);
time_start = time.time()
seconds = 0
minutes = 0
while True:
time.sleep(1)
seconds = int(time.time() - time_start) - minutes * 60#YHVH
#HEAT TO BE UNDER clean with bet incense and "natron ; no member of thine #hath any the ordering of my "'territory .'" The same idea
if seconds==1:
pyautogui.click(900,340);
break;
#sys.exit();
time.sleep(37);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | desertnaut |
