nokogiri

Insert Text After Specific XML Tag in Nokogiri

寵の児 提交于 2019-12-25 05:15:07
问题 I'd like to create the following XML: <?xml version="1.0"> <foo> <bar/> TEXT GOES HERE </foo> The structure is pretty simple to build with Nokogiri: builder = Nokogiri::XML::Builder.new do |xml| xml.foo { xml.bar {} } end puts builder.to_xml What I can't figure out is how to insert the TEXT GOES HERE string inside <foo> but after <bar/> . Obviously, xml.foo("TEXT GOES HERE") produces the text before <bar> . What am I missing? 回答1: You want the text method: require 'nokogiri' builder =

Insert Text After Specific XML Tag in Nokogiri

江枫思渺然 提交于 2019-12-25 05:15:03
问题 I'd like to create the following XML: <?xml version="1.0"> <foo> <bar/> TEXT GOES HERE </foo> The structure is pretty simple to build with Nokogiri: builder = Nokogiri::XML::Builder.new do |xml| xml.foo { xml.bar {} } end puts builder.to_xml What I can't figure out is how to insert the TEXT GOES HERE string inside <foo> but after <bar/> . Obviously, xml.foo("TEXT GOES HERE") produces the text before <bar> . What am I missing? 回答1: You want the text method: require 'nokogiri' builder =

Searching savon response as nokogiri document returns an empty array

女生的网名这么多〃 提交于 2019-12-25 03:19:25
问题 I try to parse savon's response as nokokiri document c = Savon.client(wsdl: 'http://test.fedresurs.ru/MessageService/WebService.svc?wsdl', digest_auth: ['demowebuser', 'Ax!761BN'], namespace: "http://tempuri.org/", namespace_identifier: :tem, log: true) r = c.call(:get_trade_messages, message: {'tem:startFrom' => DateTime.now-1}) r.doc.search("TradePlace") and it returns an empty array. What I'm doing wrong? May be I should deal somehow with namespaces? But, how?. Examples, that I found in

Parse html into Rails without new record every time?

我的梦境 提交于 2019-12-25 03:12:50
问题 I have the following code which is parsing a HTML table as simply as possible. # Timestamp (Column 1 of the table) page = agent.page.search("tbody td:nth-child(1)").each do |item| Call.create!(:time => item.text.strip) end # Source (Column 2 of the table) page = agent.page.search("tbody td:nth-child(2)").each do |item| Call.create!(:source => item.text.strip) end # Destination (Column 3 of the table) page = agent.page.search("tbody td:nth-child(3)").each do |item| Call.create!(:destination =>

Rails nokogiri parse XML file

心已入冬 提交于 2019-12-25 03:12:36
问题 I'm a little bit confused: could not find in web good examples of parsing xml with nokogiri... example of my data: <?xml version="1.0" encoding="UTF-8"?> <root> <rows SessionGUID="6448680D1"> <row> <AnalogueCode>0451103079</AnalogueCode> <AnalogueCodeAsIs>0451103079</AnalogueCodeAsIs> <AnalogueManufacturerName>BOSCH</AnalogueManufacturerName> <AnalogueWeight>0.000</AnalogueWeight> <CodeAsIs>OC90</CodeAsIs> <DeliveryVariantPriceAKiloForClientDescription />

Why do I get a Nokogiri crash and MemoryError: negative re-allocation size?

。_饼干妹妹 提交于 2019-12-24 17:57:46
问题 I've got a crawler that runs fine locally, but when I run it on a XL EC2 instance, I'm getting a MemoryError: negative re-allocation size error. I've searched the web but can't find anything helpful. Any thoughts on what could be wrong? 回答1: I believe we were getting this error because of our disk was full. 来源: https://stackoverflow.com/questions/10838475/why-do-i-get-a-nokogiri-crash-and-memoryerror-negative-re-allocation-size

Why do I get a Nokogiri crash and MemoryError: negative re-allocation size?

荒凉一梦 提交于 2019-12-24 17:56:03
问题 I've got a crawler that runs fine locally, but when I run it on a XL EC2 instance, I'm getting a MemoryError: negative re-allocation size error. I've searched the web but can't find anything helpful. Any thoughts on what could be wrong? 回答1: I believe we were getting this error because of our disk was full. 来源: https://stackoverflow.com/questions/10838475/why-do-i-get-a-nokogiri-crash-and-memoryerror-negative-re-allocation-size

using nokogiri to parse google picasa api xml - namespacing issue?

烂漫一生 提交于 2019-12-24 15:56:41
问题 I am trying to get some data from some google picasa xml, and am having a bit of trouble.. Here is the actual xml (containing just one entry): http://pastie.org/1736008 Basically, I would like to collect a few of the gphoto attributes, so ideally what I would like to do is: doc.xpath('//entry').map do |entry| {:id => entry.children['gphoto:id'], :thumb => entry.children['gphoto:thumbnail'], :name => entry.children['gphoto:name'], :count => entry.children['gphoto:numphotos']} end However, this

Can't install Nokogiri 1.4.3 gem

六月ゝ 毕业季﹏ 提交于 2019-12-24 13:20:54
问题 Can't install nokogiri 1.4.3 gem. Nokogiri 1.6.6.2 installs without a problem. Using latest RVM on Ubuntu. pm@sniegas:~$ gem install nokogiri -v '1.4.3' Fetching: nokogiri-1.4.3.gem (100%) Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /home/pm/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150519-7580-2yzgsg.rb extconf.rb *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack

How to pull data from KML/XML?

拈花ヽ惹草 提交于 2019-12-24 11:52:37
问题 I have some data I converted to XML from a KML file and I was curious how to use PHP or Ruby to get back things like the neighborhood names and coordinates. I know when they have a tag around them like so. <cities> <neighborhood>Gotham</neighborhood> </cities> but the data is unfortunately formatted as: <SimpleData name="neighborhd">Colgate Center</SimpleData> instead of <neighborhd>Colgate Center</neighborhd> This is the KML source: How can I use PHP or Ruby to pull data from something like