点此免费加入Python网络爬虫学习交流QQ群:428518750
向ChatGPT循环提交请求并获取请求结果:
from playwright.sync_api import Playwright, sync_playwright, expect
import json
def run(playwright: Playwright) -> None:
cookies=[]
with open('cookies.json', 'r') as f:
cookies = json.load(f)
print(cookies)
browser = playwright.chromium.launch(headless=False)
context = browser.new_context(storage_state='cookies.json')
page = context.new_page()
page.goto("https://chatgpt.***.com/")
page.wait_for_timeout(5000)
question_list=['python','sql','oracle','mysql']
for qst in question_list:
page.get_by_role("textbox").fill(qst)
page.get_by_role("textbox").press("Enter")
page.wait_for_timeout(1000)
text1 = "1"
text2 = "2"
while(text1 != text2):
t1_list=page.query_selector_all('uni-view > uni-view.other-content-item > uni-view > uni-view.other-news')
if(len(t1_list)>0):
text1=t1_list[-1].inner_text()
page.wait_for_timeout(3000)
t2_list=page.query_selector_all('uni-view > uni-view.other-content-item > uni-view > uni-view.other-news')
if(len(t2_list)>0):
text2=t2_list[-1].inner_text()
print(text1)
page.wait_for_timeout(200000)
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
本站所有内容均为原创,本站保留所有权利。仅允许非商业用途的转载,但必须注明来源网站、作者、来源链接!否则,由此造成的一切后果,由转载方承担!
干货分享、技术提升、面试笔试、学习交流,欢迎关注公众号:xuesql。QQ学习交流群:209942678。