Message Boards Message Boards

0
|
1509 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to set proxies for the browser started by StartWebSession?

Posted 1 year ago

I try to set the proxy as follows, but failed:

In[209]:= (*
https://mathematica.stackexchange.com/questions/242495/chrome-driver-error-in-startwebsession
$DefaultProxyRules
*)
(*Set a proxy specification for the HTTP protocol:*)
origUseProxy=$DefaultProxyRules["UseProxy"];
origHttpProxy=$DefaultProxyRules["HTTP"];
origHttpsProxy=$DefaultProxyRules["HTTPS"];
origSocksProxy=$DefaultProxyRules["Socks"];

$DefaultProxyRules["HTTP"] = {"127.0.0.1", 8080};
$DefaultProxyRules["HTTPS"] = {"127.0.0.1", 8080};
$DefaultProxyRules["Socks"] = {"127.0.0.1", 18889};

(*Because the "UseProxy" value acts like a master switch, that HTTP proxy specification will not take effect unless "UseProxy" is set to Manual:*)
$DefaultProxyRules["UseProxy"] = Manual;


In[224]:= (*Use Visible->False to run the browser in "\[AliasDelimiter]ess" mode, where the browser window does not actually become visible:*)
(*session = StartWebSession["Chrome", Visible -> False];*)
session = StartWebSession[]
page = WebExecute[
  "OpenPage" -> 
   "https://www.cryst.ehu.es/cgi-bin/cryst/programs/nph-getgen?list=new&what=gen&gnum=227"];
inputs = WebExecute[session, "LocateElements" -> "Tag" -> "Input"];
WebExecute[session, "ClickElement" -> Last@inputs];

anchors = WebExecute["LocateElements" -> "Tag" -> "a"];
Select[WebExecute["PageHyperlinks"], StringContainsQ["gnum="]]
DeleteObject[session];

Out[224]= Failure["StartWebSession", <|"MessageTemplate" -> "Unable \
to start `driver` driver process", 
  "MessageParameters" -> <|"driver" -> "Chrome"|>|>]

During evaluation of In[224]:= URLRead::invhttp: Empty reply from server.

During evaluation of In[224]:= WebExecute::argr: The arguments for WebExecute are not valid.

During evaluation of In[224]:= Last::normal: Nonatomic expression expected at position 1 in Last[$Failed].

During evaluation of In[224]:= WebExecute::argr: The arguments for WebExecute are not valid.

During evaluation of In[224]:= URLRead::invhttp: Empty reply from server.

During evaluation of In[224]:= URLRead::invhttp: Empty reply from server.

During evaluation of In[224]:= StringContainsQ::strse: String or list of strings expected at position 1 in StringContainsQ[gnum=][<|MessageTemplate->`command` failed.,MessageParameters-><|command->PageHyperlinks|>|>].

Out[229]= Failure[]

During evaluation of In[224]:= DeleteObject::nim: Cannot delete object Failure[\[WarningSign]   Message:  Unable to start Chrome driver process
Tag:    StartWebSession

].

Any hints for fixing this problem?

P.S. This question is initially posted here. But according to Daniel Lichtblau's suggestion, it is appropriate to start a new discussion.

Regards, Zhao

POSTED BY: Hongyi Zhao
2 Replies
Posted 1 month ago

Setting proxies can be a bit tricky, but here's a general approach you can try: Define your proxy settings: proxySettings = { "UseProxy" -> True, "HTTP" -> "http://your-proxy-address:port", "HTTPS" -> "https://your-proxy-address:port" }; If you're still having trouble, you might consider reaching out to a Proxy service provider for more specific guidance on configuring proxies for your browser. They can provide you with detailed instructions based on your network setup. I hope this helps, and let me know if you have any other questions!

POSTED BY: Overnhou Max
Posted 1 month ago

But I don't know how to integrate your tips into my above testing code. Any more tips or a minimal working example will be helpful.

POSTED BY: Hongyi Zhao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract