[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 求助将网站源码指定内容输出

有偿:50元

我现在有N个URL,存放在1.txt里

批处理:判断URL源码中是否包含qq.com 这个关键词的链接

网页源码举例
<a href="https://jq.qq.com/?_wv=102700&k=123123" target="_blank"><img src="images/q1.png"></a>

如果包含,则输出 https://jq.qq.com/?_wv=102700&k=123123   保存到2.txt记事本中

1.txt中所有的URL都要分析,分析后输出到2.txt,一个一行


有会的加V:LHY7788945

  1. <# :
  2. cls&echo off&cd /d "%~dp0"&mode con lines=5000
  3. powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
  4. pause
  5. exit
  6. #>
  7. $findword="qq.com";
  8. $txtfile1=".\1.txt";
  9. $txtfile2=".\2.txt";
  10. function gethtml($u){
  11.     $t='';
  12.     for($j=1;$j -le 3;$j++){
  13.         try{
  14.             $req=Invoke-WebRequest -Uri $u;
  15.             $t=$req.Content;
  16.             break;
  17.         }catch{
  18.             write-host ('第'+$j.ToString()+'次获取网页源码失败');
  19.             start-sleep -Seconds 3;
  20.         }
  21.     }
  22.     return $t;
  23. }
  24. $newfolder=".\源码";
  25. if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
  26. $enc=[Text.Encoding]::GetEncoding('GB2312');
  27. $fs=New-Object System.IO.FileStream($txtfile2, [System.IO.FileMode]::Create);
  28. $sw=New-Object System.IO.StreamWriter($fs, $enc);
  29. $text=[IO.File]::ReadAllLines($txtfile1, $enc);
  30. for($i=0;$i -lt $text.count;$i++){
  31.     write-host $text[$i];
  32.     $html=gethtml $text[$i];
  33.     $outfile=$newfolder.trimend('\')+'\'+($i+1).ToString()+'.txt';
  34.     [Io.File]::WriteAllText($outfile, $html, [Text.Encoding]::GetEncoding('UTF-8'))
  35.     $m=[regex]::matches($html, 'href=[''"]?([^''" ]+)');
  36.     $isexist=$false;
  37.     foreach($it in $m){
  38.         if($it.groups[1].value.Contains($findword)){
  39.             $sw.WriteLine($it.groups[1].value);
  40.             $sw.Flush();
  41.             $isexist=$true;
  42.         }
  43.     }
  44.     if($isexist){
  45.         write-host 'match' -ForegroundColor green;
  46.     }
  47. }
  48. $sw.Close();
  49. $fs.Close();
复制代码
提供bat代写,为你省时省力省事,支付宝扫码头像支付
微信: unique2random

TOP

返回列表