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