skip to Main Content

I have been through the other answers but none of them seemed to help me. I am just starting out with programming.

import jdk.incubator.http.HttpClient;
import jdk.incubator.http.HttpResponse;
import org.apache.*;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;


public class app {
    public static void main(String[] args) throws JSONException, IOException {
        HttpClient client = HttpClients.createDefault();
        HttpGet get = new HttpGet("https://www.youtube.com/watch?v=Qdjna4Nh7DM");
        HttpResponse res = client.execute(get);

        String strng = EntityUtils.toString(res.getEntity());
        System.out.println(strng);
        String str1 = "playability";
        if(strng.toLowerCase().contains(str1.toLowerCase())){
            System.out.println("waah");
        }
        else{
            System.out.println("naah");
        }
    }
}

I am trying to get the data out of a site and see if it contains the world playability in it.

The problem I am having is that intellij cannot resolve symbol apache here.

I have built a maven project with the following pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>driverscrape</groupId>
    <artifactId>driverscrape</artifactId>
    <version>1.0-SNAPSHOT</version>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Am I missing something? Is there something else that I should do? Please guide me!

2

Answers


  1. Try adding the apache http package as a dependency in your pom.xml

    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.3.6</version>
    </dependency>   
    

    Note:please check the exact package name

    Login or Signup to reply.
  2. Try adding this to your pom.xml, right between </build> and </project>

    <dependencies>
        <dependency>
              <groupId>org.apache.httpcomponents</groupId>
              <artifactId>httpclient</artifactId>
              <version>4.5.5</version>
        </dependency>
    </dependencies>
    

    Explanation: You are missing the library. You need to tell your project which library you need, how it is called and which version you want.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search