au3抓取糗事百科网站

网址:‘http://www.qiushibaike.com/8hr/page/‘ & $pagenum & ‘?s=4512150‘

#include <IE.au3>
#include <File.au3>
#include <String.au3>
#include <Array.au3>
#include <Debug.au3>
#include <Date.au3>

;code try to collect Qiushibaike stories in qiushibaike.com
Local $strUrl1 = "http://www.qiushibaike.com/8hr/page/2?s=4512150"
Local $filename1 = "qiushibaike"
$filename1 = $filename1 & ‘_‘ & @MON
$filename1 = $filename1  & @MDAY
$filename1 = $filename1 & ‘.txt‘
Local $filesave = @TempDir & "\qb.html"
Local $pageindex
Local $startindex = 2
Local $endindex = 10
Local $sHTML
Local $storycount = 0
_FileCreate($filename1)
Local $file = FileOpen($filename1, 1)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
 EndIf
For $pageindex = $startindex To $endindex Step 1
   $strUrl1 = MakeUpUrl($pageindex)
   Local $hDownload = InetGet($strUrl1, $filesave, 1, 1)
   Do
       Sleep(250)
   Until InetGetInfo($hDownload, 2)
   Local $nBytes = InetGetInfo($hDownload, 0)
   InetClose($hDownload)
  ConsoleWrite ($pageindex & ‘/‘ &  $endindex &" --- down bytes = " &$nBytes & @LF)
  $fsize = $nBytes
  ;ConsoleWrite($pageindex & ‘- filesize = ‘& $fsize & @LF)
  $ftemp = FileOpen($filesave, 0)
  $getsize=    FileGetSize ($filesave)
  $sHTML = FileRead($ftemp, $getsize)
  FileClose($ftemp)
  FileDelete($filesave)
  Local $aArray = StringRegExp($sHTML, ‘(?<=<span>)\n+[^/]+\n+(?=</span>)‘, 3)
  ConsoleWrite("    array size = " & UBound($aArray) & @CRLF)
  For $i = 0 To (UBound($aArray) - 1) Step 1
     Local $item = $aArray[$i]
     If StringLen($item) > 0 Then
    $strnum = $storycount +1
    $strnum = $strnum & "." &@CRLF
    FileWrite($file, $strnum)
    $storycontent = StringReplace($item, @LF, ‘‘)
     $storycontent = $storycontent & @CRLF
     FileWrite($file, $storycontent)
     $storycount = $storycount + 1
     EndIf
     Next
   Next
FileClose($file)
MsgBox(0, "QSBK", "Complete, story count = "&$storycount & ‘, story=‘ & $filename1)
Exit
Func MakeUpUrl($pagenum)
   $strUrl = ‘http://www.qiushibaike.com/8hr/page/‘ & $pagenum & ‘?s=4512150‘
   return $strUrl
   EndFunc
时间: 2025-02-01 08:43:22

au3抓取糗事百科网站的相关文章

Python爬虫--抓取糗事百科段子

今天使用python爬虫实现了自动抓取糗事百科的段子,因为糗事百科不需要登录,抓取比较简单.程序每按一次回车输出一条段子,代码参考了 http://cuiqingcai.com/990.html 但该博主的代码似乎有些问题,我自己做了修改,运行成功,下面是代码内容: 1 # -*- coding:utf-8 -*- 2 __author__ = 'Jz' 3 import urllib2 4 import re 5 6 #糗事百科爬虫类 7 class QSBK: 8 #初始化 9 def __

HtmlAgilityPack抓取糗事百科內容

本文实例讲述了C#使用HtmlAgilityPack抓取糗事百科内容的方法.分享给大家供大家参考.具体实现方法如下: Console.WriteLine("*****************糗事百科24小时热门*******************"); Console.WriteLine("请输入页码,输入0退出"); string page = Console.ReadLine(); while (page!="0") { HtmlWeb h

bs4抓取糗事百科

抓取糗事百科内容及评论,不包含图片信息.user-agent填入浏览器的即可.user-agent对应的value,360极速浏览器的话,可以在地址栏输入about:version,回车,用户代理后面的一长串就是需要填入''里面的内容.其他的可以自行百度 import urllib.request import re from urllib import request from bs4 import BeautifulSoup #1.获取网页源代码 def get_html(url): hea

Python 网络爬虫 - 抓取糗事百科的段子(最新版)

代码 # -*- coding: cp936 -*- __author__ = "christian chen" import urllib2 import re import threading import time class Tool: def pTitle(self): return re.compile('<title.*?>(.*?)</', re.S) def pContent(self): return re.compile('<div cla

Python 简单爬虫抓取糗事百科

# coding:utf-8 import timeimport randomimport urllib2from bs4 import BeautifulSoup #引入 beautifulsoup模块 #p = 1 #定义 页url = 'http://www.qiushibaike.com/text/page/'#定义header my_headers = [    'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 F

Python爬虫爬取糗事百科段子内容

参照网上的教程再做修改,抓取糗事百科段子(去除图片),详情见下面源码: #coding=utf-8#!/usr/bin/pythonimport urllibimport urllib2import reimport threadimport timeimport sys #定义要抓取的网页#url = 'http://www.qiushibaike.com/hot/'#读取要抓取的网页#globalcontent = urllib.urlopen(url).read()#抓取段子内容#new_

芝麻HTTP:Python爬虫实战之爬取糗事百科段子

首先,糗事百科大家都听说过吧?糗友们发的搞笑的段子一抓一大把,这次我们尝试一下用爬虫把他们抓取下来. 友情提示 糗事百科在前一段时间进行了改版,导致之前的代码没法用了,会导致无法输出和CPU占用过高的情况,是因为正则表达式没有匹配到的缘故. 现在,博主已经对程序进行了重新修改,代码亲测可用,包括截图和说明,之前一直在忙所以没有及时更新,望大家海涵! 更新时间:2015/8/2 糗事百科又又又又改版了,博主已经没心再去一次次匹配它了,如果大家遇到长时间运行不出结果也不报错的情况,请大家参考最新的评

PHP爬取糗事百科首页糗事

突然想获取一些网上的数据来玩玩,因为有SAE的MySql数据库,让它在那呆着没有什么卵用!于是就开始用PHP编写一个爬取糗事百科首页糗事的小程序,数据都保存在MySql中,岂不是很好玩! 说干就干!首先确定思路 获取HTML源码--->解析HTML--->保存到数据库 没有什么难的 1.创建PHP文件"getDataToDB.php", 2.获取指定URL的HTML源码 这里我用的是curl函数,详细内容参见PHP手册 代码为 <span style="fo

爬虫二:爬取糗事百科段子

这一次我们利用BeautifulSoup进行网页的解析,方法其实跟前一次的差不多,只是这里我们爬取的是糗事百科,糗事百科有反爬机制,我们需要模拟用户来访问糗事百科网站,也就是加上头部信息headers,其实整体思路与上一篇所写爬虫的思路差不多,拿个速度可以共用. 1.首先我们在打开网页,并在网页空白处右击选择"检查"在弹出的网页里选择"Network" 2.然后按下"F5"刷新一下 3.在刷新后的页面里我们可以看到多条信息,任意选择一条信息点开