当前位置: 首页 > news >正文

专门做网站的公司叫什么比较成功的网络营销案例

专门做网站的公司叫什么,比较成功的网络营销案例,网站收录的页面被k出来,注册域名是什么意思selenium 可以动态爬取网页数据,就像真实用户操作浏览器一样,从终端用户的角度测试应用程序,WebDriver通过原生浏览器支持或者浏览器扩展直接控制浏览器 webdriver下载 因为selenuim对浏览器的版本存在兼容问题,顾需要针对指定浏…

selenium 可以动态爬取网页数据,就像真实用户操作浏览器一样,从终端用户的角度测试应用程序,WebDriver通过原生浏览器支持或者浏览器扩展直接控制浏览器

webdriver下载

因为selenuim对浏览器的版本存在兼容问题,顾需要针对指定浏览器下载指定版本。

1、添加依赖

        <dependency><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><version>4.11.0</version></dependency><dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>32.1.2-jre</version></dependency>

2、工具类

import cn.hutool.core.collection.CollectionUtil;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.springframework.stereotype.Component;import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;/*** Selenium 工具类** @author kou*/
@Slf4j
@RequiredArgsConstructor
@Component
public class SeleniumUtil {private final ReptileProperties reptileProperties;/*** 获取chromeDriver** @return chromeDriver*/public WebDriver chromeDriver() {// 加载驱动路径System.setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");// Chrome默认不允许跨机器调试,需要给启动命令加上白名单System.setProperty("webdriver.chrome.whitelistedIps", "");ChromeOptions options = new ChromeOptions();// 开启一个实验性参数excludeSwitches,用来隐藏window.navigator.webdriver返回true,这个参数必须是Listoptions.setExperimentalOption("useAutomationExtension", false);// 开启开发者模式options.setExperimentalOption("excludeSwitches", Lists.newArrayList("enable-automation"));// 发现主要是这句是关键options.addArguments("--disable-blink-features=AutomationControlled");// options.addArguments("--incognito");// options.addArguments("--disable-infobars");//options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36");options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");// 禁用沙箱options.addArguments("--no-sandbox");// 无头浏览器,这样不会打开浏览器窗口// options.addArguments("--headless");// options.addArguments("--disable-gpu");options.addArguments("--remote-allow-origins=*");// 初始化一个谷歌浏览器实例,实例名称叫driverWebDriver driver = new ChromeDriver(options);return driver;}/*** 获取edgeDriver** @return edgeDriver*/public WebDriver edgeDriver() {// 加载驱动路径System.setProperty("webdriver.edge.driver", "D:/msedgedriver.exe");EdgeOptions options = new EdgeOptions();// 开启一个实验性参数excludeSwitches,用来隐藏window.navigator.webdriver返回true,这个参数必须是Listoptions.setExperimentalOption("useAutomationExtension", false);//开启开发者模式options.setExperimentalOption("excludeSwitches", Lists.newArrayList("enable-automation"));// 发现主要是这句是关键options.addArguments("--disable-blink-features=AutomationControlled");options.addArguments("--incognito", "--disable-infobars");// options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36");options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36");// 禁用沙箱options.addArguments("--no-sandbox");// 无头浏览器,这样不会打开浏览器窗口// options.addArguments("--headless");options.addArguments("--disable-gpu");options.addArguments("--remote-allow-origins=*");// 初始化一个谷歌浏览器实例,实例名称叫driverWebDriver driver = new EdgeDriver(options);return driver;}/*** 获取firefoxDriver** @return firefoxDriver*/public WebDriver firefoxDriver() {// 加载驱动路径System.setProperty("webdriver.gecko.driver", "D:/geckodriver.exe");System.setProperty("webdriver.chrome.whitelistedIps", "");FirefoxOptions options = new FirefoxOptions();options.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36");// 无头浏览器,这样不会打开浏览器窗口options.addArguments("--headless");// 初始化一个谷歌浏览器实例,实例名称叫driverWebDriver driver = new FirefoxDriver(options);return driver;}/*** 获取表头** @param table 表格* @return 表头*/public List<String> getTableHead(WebElement table) {log.info("开始解析表头...");// 获取表头WebElement head = table.findElement(By.tagName("thead"));if (null == head) {return Collections.emptyList();}List<WebElement> headths = head.findElements(By.tagName("th"));List<String> headList = new ArrayList<>(headths.size());headths.forEach(t -> {headList.add(t.getText());});log.info("表头解析完成!!!");return headList;}/*** 获取表数据** @param table 表格* @return 表头*/public List<List<String>> getTableBody(WebElement table) {log.info("开始解析表数据...");// 获取表头WebElement tbody = table.findElement(By.tagName("tbody"));if (null == tbody) {return Collections.emptyList();}// 获取body数据行List<WebElement> bodyTrs = tbody.findElements(By.tagName("tr"));if (CollectionUtil.isEmpty(bodyTrs)) {return Collections.emptyList();}List<List<String>> bodyDatas = new ArrayList<>(bodyTrs.size());bodyTrs.stream().forEach(r -> {List<WebElement> tds = r.findElements(By.tagName("td"));List<String> rows = new ArrayList<>(tds.size());tds.forEach(d -> {rows.add(d.getText());});bodyDatas.add(rows);});log.info("表数据解析完成!!!");return bodyDatas;}/*** 将参数转化为路径参数** @param params 参数* @return 路径参数*/public String convertPathParams(Map<String, Object> params) {if (CollectionUtil.isEmpty(params)) {return "";}StringBuffer path = new StringBuffer();for (Map.Entry<String, Object> p : params.entrySet()) {path.append(p.getKey()).append("=").append(p.getValue().toString()).append("&");}return path.substring(0, path.length() - 1);}}

3、爬取数据

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;/*** 数据接口实现类** @author kou*/
@Slf4j
@RequiredArgsConstructor
@Service
public class DataServiceImpl {private final SeleniumUtil seleniumUtil;/*** 获取页面数据** @return 数据*/@Overridepublic Map<String, Object> getHtmlData() {try {Map<String, Object> data = new HashMap<>();String url = "url";Map<String, Object> params = new HashMap<>();params.put("pageNum", 1);params.put("pageSize", 1000);String fullUrl = url + seleniumUtil.convertPathParams(params);WebDriver driver = seleniumUtil.firefoxDriver();driver.get(fullUrl);// 打开一个站点log.info("开始访问:{}", fullUrl);driver.get(fullUrl);String title = driver.getTitle();log.info("网页:{}", title);// 获取表格数据WebElement table = driver.findElement(By.id("table"));//显式等待,针对某个元素等待,等待超时时间100s,2s检测一次WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(100), Duration.ofSeconds(2));// wait.until(ExpectedConditions.presenceOfElementLocated(By.id("table")));wait.until(new ExpectedCondition<WebElement>() {@Overridepublic WebElement apply(WebDriver text) {log.info("开始检查tbody数据是否已加载");WebElement table = text.findElement(By.id("table")).findElement(By.tagName("tbody"));if (!table.isDisplayed()) {log.info("检查结果:tbody数据未加载完,等待加载...");return null;}log.info("检查结果:tbody数据加载完成!!!");return table;}});// 获取表头List<String> headList = seleniumUtil.getTableHead(table);List<List<String>> bodyList = seleniumUtil.getTableBody(table);data.put("header", headList);data.put("body", bodyList);driver.close();return data;} catch (Exception e) {throw new RuntimeException(e);}}}

http://www.hengruixuexiao.com/news/34098.html

相关文章:

  • 广安网站建设公司百度指数的作用
  • 网站制作三级页面打造龙头建设示范
  • 建筑工程资料网站营销型网站外包
  • wordpress复古三栏主题推广关键词优化公司
  • 计算机网站开发毕业论文题目最近七天的新闻重点
  • 西宁做网站网站建设公司简介
  • 产品营销型网站建设建设公司网站大概需要多少钱?
  • 网站建设任务百度引擎入口官网
  • 刚刚封城最新消息2021北京网络优化推广公司
  • 网站添加qq聊天绍兴seo排名外包
  • 吉林沈阳网站建设品牌seo培训咨询
  • 东莞做创意网站百度爱采购官方网站
  • 自媒体平台前十名长沙靠谱seo优化
  • 济南专业网站优化百度站长联盟
  • 平阳县住房和城乡规划建设局网站网络推广怎么做方案
  • 网站建设费用报价单重庆seo教程
  • 网站添加属性泉州搜索推广
  • 微盟登录家庭优化大师
  • 淘宝客网站用什么软件做百度怎么推广自己的视频
  • 企业做个网站多少钱淮安百度推广公司
  • 苏州做学校网站的黄页88网推广服务
  • 广州做网站那家好搜索引擎营销的方法不包括
  • 机械网站建设方案一台电脑赚钱的门路
  • 个人网站注册流程北京百度关键词排名
  • wordpress写文章教程苏州seo网站推广哪家好
  • 软件开发工资一般多少钱一个月吉林seo外包
  • 自己可做以做网站吗福州百度快照优化
  • 河北网站制作公司电话b2b平台推广
  • 旅游网站开发现状网站关键词优化怎么弄
  • 可以自己做网站卖东西注册网站平台要多少钱