ruby+nokogori抓取糗事百科前10頁並存儲進資料庫示例
来源:互联网 发布:网络推广部门口号 编辑:程序博客网 时间:2024/05/29 13:37
ruby+nokogori抓取糗事百科前10頁並存儲進資料庫示例
#encoding:utf-8require "open-uri"require "nokogiri"require "mysql"@dbh=Mysql.real_connect("localhost","root","dengli","pachong")@file=open("qb.txt","w")def getQiubai(url)data=open(url){|f| f.read}doc=Nokogiri::HTML(data)doc.css('div.block.untagged.mb15.bs2').each{|p|content=p.css('div.content').text@file.puts("#{content}\n")img=p.css('div.thumb img').each{|img|imgAddr=img.attr('src') @file.puts("#{imgAddr}\n")time=Time.nowsql="INSERT INTO qiushibaike (`body`,`img`,`time`) VALUES ('#{content}','#{imgAddr}','#{time}')"@dbh.query(sql)}}endfor i in 1..10@file.puts("這是第#{i}頁")url="http://www.qiushibaike.com/8hr/page/#{i}"getQiubai(url)end
0 0
- ruby+nokogori抓取糗事百科前10頁並存儲進資料庫示例
- 爬虫实战--抓取糗事百科前10页数据
- Python3抓取糗事百科
- 实战抓取糗事百科
- Python抓取糗事百科
- java抓取糗事百科内容
- 使用scrapy抓取糗事百科
- 使用scrapy抓取糗事百科
- Python抓取糗事百科邀请码
- Python网络爬虫抓取糗事百科
- python抓取糗事百科的段子
- 用urllib、BeautifulSoup抓取糗事百科段子
- Python实现抓取糗事百科的段子
- python抓取糗事百科段子 图片
- python抓取糗事百科文字内容
- python bs4 抓取糗事百科资源
- Python - 静态页面抓取(抓取‘糗事百科’段子)
- 糗事百科
- VBA第5课 select多条件判断
- 《Effective java》读书笔记——过期引用
- lua gc
- CF #301 504C C. Ice Cave BFS
- 利用enum实现swtich String类型
- ruby+nokogori抓取糗事百科前10頁並存儲進資料庫示例
- 1078FatMouse and Cheese
- Ruby字元串、條件、循環、數組、Hash、類基本操作筆記
- 傻瓜教程:把iPhone程序连接真机调试
- H.图像匹配(安徽省2014年“京胜杯”大学生程序设计竞赛)
- Ruby中的反射(Reflection)應用實例
- 2840: 编程题AB-面粉质量差
- Linux下利用script命令录制并回放终端会话
- vs2010 单文档MFC 通过加载位图文件作为客户区背景