6
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ 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 help center! 3) When you see good questions and answers, vote them up by clicking the vote triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ Commented Dec 24, 2016 at 17:08
  • $\begingroup$ 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 $\endgroup$ Commented Dec 25, 2016 at 6:39
  • $\begingroup$ 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/… $\endgroup$ Commented Mar 1, 2017 at 15:23

1 Answer 1

5
$\begingroup$

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!

$\endgroup$
1
  • $\begingroup$ If you are using URLRead instead of URLFetch, is the cookie correctly set automatically? (see CookieFunction) $\endgroup$ Commented Oct 30, 2017 at 21:35

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.