1

I'm writing a small program and I want to fetch an element from a website. I've followed many tutorials to learn how to write this code with jSoup. An example of what I'm trying to print is "Monday, November 19, 2018 - 3:00pm to 7:00pm". I'm running into the error

org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=https://my.cs.ubc.ca/course/cpsc-210

Here is my code:

public class WebPageReader {
private String url = "https://my.cs.ubc.ca/course/cpsc-210";
private Document doc;

public void readPage(){
    try {
        doc = Jsoup.connect(url).
                userAgent("Mozilla/5.0")
                .referrer("https://www.google.com").timeout(1000).followRedirects(true).get();
        Elements temp=doc.select("span.date-display-single");
        int i=0;
        for (Element officeHours:temp){
            i++;
            System.out.println(officeHours);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
  }
}

Thanks for the help.

1 Answer 1

1

Status 403 means your access is forbidden.

Please make sure you have an access to https://my.cs.ubc.ca/course/cpsc-210

I have tried to access https://my.cs.ubc.ca/course/cpsc-210 from browser. It returns Error Page. I think you need to use credential to access it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.