需要的maven的配置:
<?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>BrowserMod_Proxy</groupId>
<artifactId>BrowserMod_Proxy</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.lightbody.bmp</groupId>
<artifactId>browsermob-core</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.2.0</version>
</dependency>
</dependencies>
</project>
package ljxwtl.cn;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.core.har.HarEntry;
import net.lightbody.bmp.proxy.CaptureType;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.List;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) throws Exception {
BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxy);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true);
chromeOptions.setProxy(seleniumProxy);
WebDriver driver = new ChromeDriver(chromeOptions);
browserMobProxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
browserMobProxy.setHarCaptureTypes(CaptureType.RESPONSE_CONTENT);
browserMobProxy.newHar("tengxu");
driver.get("https://v.qq.com/x/cover/nw4efw6vdp1t7kx.html");
Har har = browserMobProxy.getHar();
List<HarEntry> entries = har.getLog().getEntries();
for (HarEntry harEntry : entries){
if (harEntry.getRequest().getUrl().matches("https://.+?\\.m3u8.*")){
}
System.out.println(harEntry.getRequest().getUrl());
System.out.println(harEntry.getResponse().getContent().getMimeType());
System.out.println(harEntry.getResponse().getContent().getText());
}
}
}