相关疑难解决方法(0)

Nokogiri,open-uri和Unicode角色

我正在使用Nokogiri和open-uri来抓取网页上标题标签的内容,但是在重音字符方面遇到了麻烦.处理这些问题的最佳方法是什么?这是我正在做的事情:

require 'open-uri'
require 'nokogiri'

doc = Nokogiri::HTML(open(link))
title = doc.at_css("title")
Run Code Online (Sandbox Code Playgroud)

此时,标题如下所示:

抹布\ 303\271

代替:

肉酱

我怎样才能让nokogiri返回正确的字符(例如在这种情况下为ù)?

这是一个示例网址:

http://www.epicurious.com/recipes/food/views/Tagliatelle-with-Duck-Ragu-242037

ruby unicode screen-scraping open-uri nokogiri

25
推荐指数
4
解决办法
2万
查看次数

R中的特殊字符

我正在努力能够将对话的成绩单读入R.然而,我遇到了一些特殊字符,例如卷曲引号en和em破折号等.通常我首先用微软产品替换这些特殊字符replace.通常我用纯文本替换特殊字符,但在某些情况下希望用其他字符替换它们(即我用"{替换"}).这很繁琐,并不总是彻底.如果我可以将原稿转录成R,然后使用Encoding将其编码切换为可识别的unicode格式,我可以将gsub它们取出并用纯文本版本替换它们.但是文件是以某种我不理解的方式读入的.这是我的数据可能是什么的xlsx:

http://dl.dropbox.com/u/61803503/test.xlsx

这是.xlsx文件中的内容

text                              num
“ ” curly quotes                    1
en dash (–) and the em dash (—)     2
‘ ’ curly apostrophe-ugg            3
…  ellipsis are uck in R            4
Run Code Online (Sandbox Code Playgroud)

这可以通过以下方式读入R:

URL <- "http://dl.dropbox.com/u/61803503/test.xlsx"
library(gdata) 
z <- read.xls(URL, stringsAsFactors = FALSE) 
Run Code Online (Sandbox Code Playgroud)

结果是:

                                 text num
1                “ †curly quotes    1
2 en dash (–) and the em dash (—)   2
3        ‘ ’ curly apostrophe-ugg   3
4          …  ellipsis are uck in R   4
Run Code Online (Sandbox Code Playgroud)

所以我尝试使用 …

r

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

nokogiri ×1

open-uri ×1

r ×1

ruby ×1

screen-scraping ×1

unicode ×1