from playwright.sync_api import sync_playwright
while total_post < 1000:
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
# browser = p.chromium.launch()#顯示瀏覽器
page = browser.new_page()
url = f'https://www.sehuatang.org/forum.php?mod=forumdisplay&fid=95&orderby=dateline&orderby=dateline&filter=dateline&page='+str(page_count)
page.goto(url)
browser = p.chromium.launch(headless=False)
# browser = p.chromium.launch()#顯示瀏覽器
page = browser.new_page()
因為上面這幾行我只要執行一次就可以了
但是後面一些對網頁的操作在下一次while還是需要執行
那該如何讓上面這幾句只執行一次不被重複執行?
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
while total_post < 1000:
url = f'https://www.sehuatang.org/forum.php?mod=forumdisplay&fid=95&orderby=dateline&orderby=dateline&filter=dateline&page='+str(page_count)
page.goto(url)
這樣才對吧...