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

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$
    – Karsten7
    Oct 30, 2017 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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