"<-----/strings/----->" my ruby http client, link search.

B

Bigmac Turdsplash

im not sure how to ask this question...
Imagen the body of a webpage as the string im searching threw...

[body]
<a href="htxp://www.xxxxxx/not-this-one/xxxxx/xxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/nope/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/or-this/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>[/body]

i need to find this /files/ then on the left side and right side there
are quotes "<------/files/------>"

i need all the data in between each quote, this will be a download link
my script will need to find...

im not sure how to do this... please help if you can
 
M

Michael Fellinger

im not sure how to ask this question...
Imagen the body of a webpage as the string im searching threw...

[body]
<a href="htxp://www.xxxxxx/not-this-one/xxxxx/xxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/nope/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/or-this/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>[/body]

i need to find this /files/ then on the left side and right side there
are quotes "<------/files/------>"

i need all the data in between each quote, this will be a download link
my script will need to find...

im not sure how to do this... please help if you can

require 'nokogiri'
text = <<HTML
<a href="htxp://www.xxxxxx/not-this-one/xxxxx/xxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/nope/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/or-this/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"> said:
Nokogiri::HTML(text).xpath('//a[contains(@href,"/files/")]').map{|a| a[:href] }
=> ["htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx"]
 
R

Robert Klemme

im not sure how to ask this question...
Imagen the body of a webpage as the string im searching threw...

[body]
<a href="htxp://www.xxxxxx/not-this-one/xxxxx/xxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/nope/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>
<a href="htxp://www.xxxxxx/or-this/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15</a>[/body]

i need to find this /files/ then on the left side and right side there
are quotes "<------/files/------>"

i need all the data in between each quote, this will be a download link
my script will need to find...

im not sure how to do this... please help if you can

require 'nokogiri'
text = <<HTML
<a href="htxp://www.xxxxxx/not-this-one/xxxxx/xxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/nope/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"></a>
<a href="htxp://www.xxxxxx/or-this/xxxxxxx/xxxxxxxx" onclick=""
style="font-size:15"> said:
Nokogiri::HTML(text).xpath('//a[contains(@href,"/files/")]').map{|a| a[:href] }
=> ["htxp://www.xxxxxx/files/xxxxxxx/xxxxxxxx"]

Or even

doc.xpath('//a[contains(@href,"/files/")]/@href').map(&:value)

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,237
Latest member
AvivMNS

Latest Threads

Top