https://browsermob-proxy-py.readthedocs.io/en/stable/
https://github.com/lightbody/browsermob-proxy
import settings
from browsermobproxy import Server
from selenium.webdriver import DesiredCapabilities
config = settings.Config
server = Server(config.BROWSERMOB_PATH)
server.start()
proxy = server.create_proxy()
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxy.proxy)
chrome_options.add_argument('--headless')
capabilities = DesiredCapabilities.CHROME.copy()
capabilities['acceptSslCerts'] = True
capabilities['acceptInsecureCerts'] = True
driver = webdriver.Chrome(options=chrome_options,
desired_capabilities=capabilities,
executable_path=config.CHROME_PATH)
proxy.new_har("sahibinden", options={'captureHeaders': True})
driver.get("https://www.sahibinden.com/en")
entries = proxy.har['log']["entries"]
for entry in entries:
if 'request' in entry.keys():
print(entry['request']['url'])
print(entry['request']['headers'])
print('\n')
proxy.close()
driver.quit()
'Python' 카테고리의 다른 글
한글 인코딩 깨지는 경우 (0) | 2023.03.02 |
---|---|
Selenium Wire (0) | 2022.12.11 |
User-agent generator (0) | 2022.12.11 |
Selenium Wire Option (2) | 2022.12.11 |
Selenium Chrome Option (0) | 2022.12.11 |