title: HTTP error fetching URL. Status=403 in Java
body: <p>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 </p>
  
  <pre><code>org.jsoup.HttpStatusException: HTTP error fetching URL. Status=403, URL=https://my.cs.ubc.ca/course/cpsc-210
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><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();
      }
    }
  }
  </code></pre>
  
  <p>Thanks for the help.</p>