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
Try adding the apache http package as a dependency in your pom.xml
Note:please check the exact package name
Try adding this to your
pom.xml
, right between</build>
and</project>
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.