[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
  1. $url = 'https://book.douban.com/subject/1023045/comments/'
  2. $response = Invoke-WebRequest -Uri $url
  3. $content = $response.ParsedHtml.getElementsByClassName('comment-content') | %{$_.outerText}
  4. Set-Content -Path "output.txt" -Value $content -Encoding Default
复制代码

TOP

回复 16# tbjx138
保存为bat文件运行
如果要用户名 时间之类的 把‘comment-content’ 换为 ‘comment’
  1. <# :
  2. @echo off
  3. cd.>output.txt
  4. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  5. pause
  6. exit
  7. #>
  8. function get-content($url, $startPage, $endPage) {
  9.      for ( $i = $startPage; $i -le $endPage; $i++) {
  10.            $pageUrl = $url+"?start=$(($i - 1) * 20)&limit=20&status=P&sort=score"
  11.            $response = Invoke-WebRequest -Uri $pageUrl
  12.            $content = $response.ParsedHtml.getElementsByClassName('comment-content') | %{$_.innerText}
  13.            Add-Content -Path "output.txt" -Value $content -Encoding UTF8
  14.      }
  15. }
  16. $url = 'https://book.douban.com/subject/1023045/comments/'
  17. get-content $url 1 11
复制代码

TOP

回复 18# tbjx138
怎么回事呢,没有改动的话应该不会出现你说的问题

TOP

这样运行后 查看两个文件的内容一样吗
  1. <# :
  2. @echo off
  3. cd.>output1.txt
  4. cd.>output2.txt
  5. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  6. pause
  7. exit
  8. #>
  9. function get-content($url, $startPage, $endPage) {
  10.      for ( $i = $startPage; $i -le $endPage; $i++) {
  11.            $pageUrl = $url+"?start=$(($i - 1) * 20)&limit=20&status=P&sort=score"
  12.            $response = Invoke-WebRequest -Uri $pageUrl
  13.            $content1 = $response.ParsedHtml.getElementsByClassName('comment-content') | %{$_.innerText}
  14.            $content2 = $response.ParsedHtml.getElementsByClassName('comment') | %{$_.innerText}
  15.            Add-Content -Path "output1.txt" -Value $content1 -Encoding UTF8
  16.            Add-Content -Path "output2.txt" -Value $content2 -Encoding UTF8
  17.      }
  18. }
  19. $url = 'https://book.douban.com/subject/1023045/comments/'
  20. get-content $url 1 11
复制代码
回复 21# tbjx138

TOP

返回列表