Closed helloHKTK closed 2 years ago
del driver.requests
will delete requests that are stored at the moment it is called, but the issue can boil down to timing.
When driver.get()
finishes for bing.com it is possible that background requests are still in-flight. These requests are thus received by Selenium Wire after del driver.requests
has been called - and so they can be seen in the subsequent log for github.com.
To be sure that all bing.com requests have completed, you'd need to put a time.sleep()
in between the twoget_request()
calls.
您好: 很高兴收到您的来信,我会尽快阅读并回复您!祝您工作顺利、生活愉快!
嗨,你找到答案了吗?我还在等。
您好: 很高兴收到您的来信,我会尽快阅读并回复您!祝您工作顺利、生活愉快!
I call "get_request()" many times in the main method, and each time I use 'del driver.requests', but it seems that 'del driver.requests' does not work, that is, when requesting 'http://github.com', it returns the result of the previous 'http://bing.com'. the code is as follows: ` from loguru import logger from seleniumwire import webdriver # Import from seleniumwire from selenium.webdriver.chrome.service import Service
def get_request(domain_url): if len(driver.requests) > 0: del driver.requests # clear previously captured requests and HAR entries logger.info(f"driver_requests_len={len(driver.requests)}") driver.get(domain_url)
path = '...' s = Service(path)
option = webdriver.ChromeOptions() option.add_argument('--headless')
driver = webdriver.Chrome(service=s, options=option) get_request('http://bing.com') get_request('http://github.com')
driver.quit() `