网页抓取qq(java+selenium-java实现qq自动登录功能并获取)
优采云 发布时间: 2022-02-22 02:24网页抓取qq(java+selenium-java实现qq自动登录功能并获取)
java+selenium-java实现qq自动登录功能并获取cookie 下面是网易云音乐的qq自动功能演示。cookie 信息将在控制台中打印出来。---->接下来就是利用这个cookie来实现网站资源爬取。
以下是qq音乐的自动登录
CSDN自动登录
源代码如下
<p>import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
public class NeteaseCloudMusicDemo {
public static void main(String[] args) {
//设置系统环境变量
// System.setProperty("webdriver.chrome.driver", "D:/Program Files (x86)/chromedriver/chromedriver.exe");
WebDriver driver = null;
try {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless"); //无浏览器模式
driver = new ChromeDriver(options);//实例化
// qq音乐
// driver.get("https://graph.qq.com/oauth2.0/authorize?response_type=code&state=state&client_id=100497308&redirect_uri=https://y.qq.com/portal/wx_redirect.html?login_type=1%26surl=https%3A%2F%2Fy.qq.com%2Fportal%2Fradio.html%23stat%3Dy_new.top.pop.logout%26stat%3Dy_new.top.pop.logout%26stat%3Dy_new.top.pop.logout%26stat%3Dy_new.top.pop.logout%26stat%3Dy_new.top.pop.logout%26use_customer_cb=0");
// csdn
// driver.get("https://graph.qq.com/oauth2.0/show?which=Login&display=pc&client_id=100270989&response_type=code&redirect_uri=https%3A%2F%2Fpassport.csdn.net%2Faccount%2Flogin%3FpcAuthType%3Dqq%26state%3Dtest");
// 网易云音乐
driver.get("https://graph.qq.com/oauth2.0/show?which=Login&display=pc&client_id=100495085&response_type=code&redirect_uri=https://music.163.com/back/qq&forcelogin=true&state=LPByMqvmCH&checkToken=9ca17ae2e6ffcda170e2e6eea5f67082abbcabe9508f9e8aa2d84e879a9aaeaa5cf38b88a3f042f589beacf92af0feaec3b92af8a8fa82f721f2ba9eb0fb5b969a8ea6c84aa1ab848cc5419188add9*敏*感*词*629a8bee9e");
// 其它的网站一般直接复制登录页面的url替代这个get即可
// driver.get("其它网站的qq登录");
final WebDriver ptlogin_iframe = driver.switchTo().frame("ptlogin_iframe");
ptlogin_iframe.findElement(By.id("switcher_plogin")).click();
final WebElement u = ptlogin_iframe.findElement(By.className("inputstyle"));
u.click();
final char[] chars = "输入qq账号".toCharArray();
for (int i = 0; i