拉取百度汉语的成语接龙脚本
来源:互联网 发布:神经网络训练算法 编辑:程序博客网 时间:2024/04/28 06:52
成语不存在或期望的接龙长度超出可查询范围时会报错,不过凑合能找到部分接龙的成语,记录之。
#encoding:GBKrequire 'net/http'require 'nokogiri'def get_alist(url)puts url$stdout.flushres = Net::HTTP.get_response(URI.parse(url))doc = Nokogiri::HTML res.bodyreturn doc.xpath("//*[@id='jielong-wrapper']")[0].css('div')[0].css('a')enddef build_long(ci,long,maxlen)url = "http://hanyu.baidu.com/s?wd=#{URI.escape(ci.encode('utf-8'))}&cf=jielong&ptype=idiom"alist = get_alist(url)i = 1alist.each do |a|if long.has_key?(a.text) thenreturn build_long(a.text,long,maxlen)elselong[a.text] = 0return long if long.size > maxlenreturn build_long(a.text,long,maxlen) if alist.size <= iendi = i + 1endendstart_chengyu = '尔虞我诈'max_length = 20long = Hash.newlong = build_long(start_chengyu,long,max_length - 1)result_file = File.open('成语接龙结果文件.txt','w')long.each do |k,v|result_file.puts kend
0 0
- 拉取百度汉语的成语接龙脚本
- 爆笑的成语接龙,呵呵
- 笔试题86. 百度笔试题——成语接龙
- 成语接龙--百度2017暑期实习生编程题
- 《成语接龙》之成语表
- 探索成语接龙
- 《成语接龙》隐私说明
- 成语接龙游戏网址
- HDU 1546 成语接龙
- 成语接龙(dfs)
- 城市成语接龙
- 成语接龙 你看过这么拽的吗?
- 绝对精彩的马字成语接龙40龙
- weiphp——成语接龙插件的对接和使用
- 我做了一个成语接龙的小程序
- 成语接龙 给一个很大的成语库 如何找出其中最长的一条线
- 成语接龙(Idiomatic Phrases Game)
- 常用汉语成语英译
- 欢迎使用CSDN-markdown编辑器
- 使用Nexus搭建Maven私服
- Update now: Macs and iPhones have a Stagefright-style bug!
- HDU 1241 DFS算法
- bzoj2728理解了好久
- 拉取百度汉语的成语接龙脚本
- 百度编辑器代码高亮
- Post、Get方法拿到的是字符串
- Gym 100114C (找循环节)
- LeetCode - 208. Implement Trie (Prefix Tree)
- Servlet文件下载
- 把框架上传cocoapods遇到的一个问题
- 通讯录之顺传和逆传
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx