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$
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$
  • $\begingroup$ If you are using URLRead instead of URLFetch, is the cookie correctly set automatically? (see CookieFunction) $\endgroup$ – Karsten 7. Oct 30 '17 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.