# Import information from a web URL that requires a username and password

I wish to use:

Import[link, "Plaintext"]


to get the plain text on a web page - however the webpage is on an internal network and requires a username and password for access.

I have tried using:

URLFetch[link, "Content", "Username" -> "myusername",  "Password" -> "mypassword"]


and then execute my Import line, but this will not work. Has anyone encountered this problem before?

• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Dec 24 '16 at 17:08
• I am not near a computer but you will need to save the cookie with your login info. There may be examples in the docs Dec 25 '16 at 6:39
• Also take a look at how the login information is send by inspecting the headers: code.tutsplus.com/tutorials/http-headers-for-dummies--net-8039 and stackoverflow.com/questions/4423061/… Mar 1 '17 at 15:23

I managed to figure out what I needed!

Indeed, the answer that worked for me is to pass along the cookie information that contains the login information for the site. Once I pinpointed which cookie was needed (I personally found this information with my Chrome browser in Advanced Settings, under “Privacy and Security” -> "Content Settings” -> “Cookies”), I used Mathematica's SetCookie function. Prior to executing the Import line, I ran something like this:

SetCookies[<|"Domain" -> "[INSERT_VALUE]", "Path" -> "[INSERT_VALUE]", "Name" -> "[INSERT_VALUE]",  "Content" -> "[INSERT_VALUE]"|>];


I replaced all “[INSERT_VALUE]" with the appropriate information about the cookie.

I then executed my

Import[link, "Plaintext"]


line, and voila! I have the information I needed!

• If you are using URLRead instead of URLFetch, is the cookie correctly set automatically? (see CookieFunction) Oct 30 '17 at 21:35