-
Hi all, I'm putting this here since there is no nodriver discussions section. I'm trying to get the browser setup with an authenticated proxy but chrome does not support credentials via browser args. I found this, where the answer from Arkadiy Bolotov is interesting. There are the same cdp methods as in his post available in Network though they are deprecated for those in Fetch. Here is my current attempt I put together this afternoon, which does intercept the requests however no authRequired events are fired as the documentation suggests.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 19 replies
-
Hi Here 2 problems arises:
Solutions:
Example of working code based of of yours: class Scraper:
main_tab: uc.Tab
def __init__(self):
uc.loop().run_until_complete(self.run())
async def run(self):
browser = await uc.start(
browser_args=[f"--proxy-server={PROXY}"],
)
self.main_tab = await browser.get("draft:,")
self.main_tab.add_handler(uc.cdp.fetch.RequestPaused, self.req_paused)
self.main_tab.add_handler(
uc.cdp.fetch.AuthRequired, self.auth_challenge_handler
)
await self.main_tab.send(uc.cdp.fetch.enable(handle_auth_requests=True))
page = await browser.get("https://www.whatismyip.com/")
await asyncio.sleep(6000)
async def auth_challenge_handler(self, event: uc.cdp.fetch.AuthRequired):
# Split the credentials
# Respond to the authentication challenge
asyncio.create_task(
self.main_tab.send(
uc.cdp.fetch.continue_with_auth(
request_id=event.request_id,
auth_challenge_response=uc.cdp.fetch.AuthChallengeResponse(
response="ProvideCredentials",
username=USERNAME,
password=PASSWORD,
),
)
)
)
async def req_paused(self, event: uc.cdp.fetch.RequestPaused):
asyncio.create_task(
self.main_tab.send(
uc.cdp.fetch.continue_request(request_id=event.request_id)
)
)
if __name__ == "__main__":
Scraper() |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hi all, I have been trying to use a proxy with nodriver for a couple of days now, without success. I tried the suggested solutions but I keep getting this error in the chrome tab: In my case, in am trying to use smartproxy residential proxies. A snippet of working code with import requests
url = 'https://ip.smartproxy.com/json'
username = 'some_user'
password = 'some_password'
proxy = f"http://{username}:{password}@es.smartproxy.com:10000"
result = requests.get(url, proxies = {
'http': proxy,
'https': proxy
})
print(result.text) A working example with import seleniumwire.undetected_chromedriver as uc
# Proxy server details
PROXYUSERNAME = 'some_user'
PROXYPASSWORD = 'some_password'
PROXYPORT = '10000'
# define your proxy credentials
proxy_username = PROXYUSERNAME
proxy_password = PROXYPASSWORD
proxy_host = 'es.smartproxy.com'
proxy_port = PROXYPORT
# form the proxy address
proxy_address = f'http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}'
# add the proxy address to proxy options
proxy_options = {
'proxy': {
'http': proxy_address,
'https': proxy_address,
}
}
if __name__ == '__main__':
# set Chrome options
options = uc.ChromeOptions()
# run Chrome in headless mode
options.headless = True
options.add_argument('--ignore-certificate-errors')
# create a Chrome instance with the proxy options
driver = uc.Chrome(
seleniumwire_options=proxy_options,
options=options,
use_subprocess=False,
)
# visit the test URL to check your proxy IP
driver.get('https://httpbin.io/ip')
ip_address = driver.find_element(By.TAG_NAME, 'body').text
print(ip_address)
# close the browser
driver.quit() However, when using these credentials with |
Beta Was this translation helpful? Give feedback.
Hi
Here 2 problems arises:
Solutions:
fire-and-forget
method e.g. do not await for sending response onreq_paused
orauth_required
. Just wrap the call intoasyncio.create_task
Example of working code based of of yours: