最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

基于Selenium+java的網(wǎng)頁(yè)爬蟲(chóng)

2023-05-27 15:52 作者:外號(hào)不可能是老瞇  | 我要投稿

1.使用selenium ide錄制

?


圖1 selenium ide

?

2.?導(dǎo)出為java文件

?

圖2 selenium export

?

3.修改代碼

package com.test;

?

// Generated by Selenium IDE

import java.util.concurrent.TimeUnit;

import org.junit.Test;

import org.junit.Before;

import org.junit.After;

import static org.junit.Assert.*;

import static org.hamcrest.CoreMatchers.is;

import static org.hamcrest.core.IsNot.not;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.remote.RemoteWebDriver;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.Dimension;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.interactions.Actions;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.Alert;

import org.openqa.selenium.Keys;

import java.util.*;

import java.net.MalformedURLException;

import java.net.URL;

import java.io.File;

import java.io.PrintWriter;

import java.io.IOException;

?

?

public class JigouTest {

File outfile = new File("D:\\Desktop\\軟件測(cè)試王廣闊20201008370\\實(shí)驗(yàn)2\\czxsy2.txt");

??private WebDriver driver;

??private Map<String, Object> vars;

??JavascriptExecutor js;

??@Before

??public void setUp() {

System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");

System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver0.29.exe");

?

????driver = new FirefoxDriver();

????js = (JavascriptExecutor) driver;

????vars = new HashMap<String, Object>();

??}

??@After

??public void tearDown() {

????driver.quit();

??}

??public String waitForWindow(int timeout) {

????try {

??????Thread.sleep(timeout);

????} catch (InterruptedException e) {

??????e.printStackTrace();

????}

????Set<String> whNow = driver.getWindowHandles();

????Set<String> whThen = (Set<String>) vars.get("window_handles");

????if (whNow.size() > whThen.size()) {

??????whNow.removeAll(whThen);

????}

????return whNow.iterator().next();

??}

??@Test

??public void jigou() throws Exception {

????driver.get("https://www.shzu.edu.cn/");

????driver.manage().window().setSize(new Dimension(1936, 1056));

????

????driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置")).click();//第一種定位方式

????WebElement opentab=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

String elementTest=opentab.getText();

//打印元素的文本

PrintWriter out = new PrintWriter(outfile, "UTF-8");// 為了避免一些亂碼問(wèn)題,制定編碼方式為 UTF-8

out.println(elementTest);


Actions action = new Actions(driver);

action.moveToElement(driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置"))).perform();

Thread.currentThread().sleep(2000);//懸停兩秒

driver.findElement(By.cssSelector("li:nth-child(2) li:nth-child(4) > a")).click();//第二種定位方式

????WebElement opentab1=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

????elementTest=opentab1.getText();

//打印元素的文本

????out.println(elementTest);


action.moveToElement(driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置"))).perform();

Thread.currentThread().sleep(2000);

????driver.findElement(By.xpath("//a[contains(text(),\'教學(xué)機(jī)構(gòu)\')]")).click();//第三種定位方式

????opentab=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

????elementTest=opentab.getText();

//打印元素的文本

????out.println(elementTest);


action.moveToElement(driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置"))).perform();

Thread.currentThread().sleep(2000);

????driver.findElement(By.xpath("//ul[@id=\'nav\']/li[2]/ul/li[5]/a")).click();//第四種定位方式

????opentab=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

????elementTest=opentab.getText();

//打印元素的文本

????out.println(elementTest);


action.moveToElement(driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置"))).perform();

????driver.findElement(By.xpath("//a[contains(@href, \'/kyjg/list.htm\')]")).click();//第五種定位方式

????opentab=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

????elementTest=opentab.getText();

//打印元素的文本

????out.println(elementTest);


action.moveToElement(driver.findElement(By.linkText("機(jī)構(gòu)設(shè)置"))).perform();

Thread.currentThread().sleep(2000);

????driver.findElement(By.xpath("//li[2]/ul/li[7]/a")).click();//第六種定位方式

????opentab=driver.findElement(By.id("wp_content_w41_0"));

//獲取元素的文本

????elementTest=opentab.getText();

//打印元素的文本

????out.println(elementTest);


out.close();// 釋放資源

????driver.close();

????

?


??}

}

4.實(shí)驗(yàn)結(jié)果

?


圖3實(shí)驗(yàn)結(jié)果圖

?

紀(jì)委機(jī)關(guān)(監(jiān)察專員辦公室)

黨委辦公室(校長(zhǎng)辦公室、向南發(fā)展辦公室)

黨委組織部(統(tǒng)戰(zhàn)部、黨校辦公室)

黨委宣傳部(精神文明辦公室)

黨委巡察工作領(lǐng)導(dǎo)小組辦公室

黨委教師工作部(人事處)

黨委學(xué)生工作部(學(xué)生處)

黨委保衛(wèi)部(武裝部、綜合治理辦公室)

黨委離退休工作部(離退休工作處)

研究生院(學(xué)科建設(shè)辦公室)

發(fā)展與規(guī)劃處

教務(wù)處

科學(xué)研究處

計(jì)財(cái)處

國(guó)際交流與合作處

實(shí)驗(yàn)室與設(shè)備管理處

基建處

資產(chǎn)管理處

審計(jì)處

后勤管理處

工會(huì)

團(tuán)委

化學(xué)化工學(xué)院

機(jī)械電氣工程學(xué)院

水利建筑工程學(xué)院

食品學(xué)院

信息科學(xué)與技術(shù)學(xué)院(網(wǎng)絡(luò)空間安全學(xué)院)

農(nóng)學(xué)院

動(dòng)物科技學(xué)院

醫(yī)學(xué)院

藥學(xué)院

生命科學(xué)學(xué)院

理學(xué)院

經(jīng)濟(jì)與管理學(xué)院

師范學(xué)院

文學(xué)藝術(shù)學(xué)院

馬克思主義學(xué)院

法學(xué)院

外國(guó)語(yǔ)學(xué)院

體育學(xué)院

商學(xué)院

繼續(xù)教育學(xué)院

兵團(tuán)教育學(xué)院

石河子大學(xué)醫(yī)學(xué)院(塔里木大學(xué))分院

孔子學(xué)院

網(wǎng)絡(luò)與信息中心

圖書(shū)館

兵團(tuán)知識(shí)產(chǎn)權(quán)信息中心(高校國(guó)家知識(shí)產(chǎn)權(quán)信息服務(wù)中心)

校醫(yī)院

分析測(cè)試中心

招標(biāo)采購(gòu)中心

教學(xué)評(píng)估中心(教師發(fā)展中心)

國(guó)際交流中心(對(duì)外交流服務(wù)中心)

期刊中心

后勤服務(wù)中心

南疆研究院

兵團(tuán)能源發(fā)展研究院

中亞教育及人文交流研究中心

政策研究室(高教研究室)

第一附屬醫(yī)院

護(hù)士學(xué)校

競(jìng)技體育運(yùn)動(dòng)學(xué)校


基于Selenium+java的網(wǎng)頁(yè)爬蟲(chóng)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
正宁县| 昌邑市| 左贡县| 托克逊县| 新河县| 阿拉善右旗| 绥棱县| 克东县| 清水河县| 连山| 酒泉市| 厦门市| 镶黄旗| 伽师县| 剑河县| 阳西县| 鸡东县| 镇沅| 万宁市| 南城县| 河北省| 永仁县| 武冈市| 满洲里市| 分宜县| 西盟| 枝江市| 马公市| 兴山县| 平果县| 泽州县| 临沂市| 澄城县| 五常市| 资源县| 靖州| 彭阳县| 绥滨县| 四子王旗| 磐石市| 蒙阴县|