Get images and text from URL

Asked 2 years ago, Updated 2 years ago, 38 views

Prerequisites/What you want to achieve

I would like to get text and images from the URL posted by the user.
(It's a function that allows you to preview the url destination when you paste url on the Twitter post screen.)
Also, I don't know if I should implement text and image acquisition on iOS or on a server site such as Rails.

I did research and thought about how to implement it

Web Displayed in WebView
Unable to retrieve as string imageview.

2) Parse the HTML of the URL destination and obtain the text url
=>
There are countless ways to write tags, so it's hard to get them.

URLObtain url information of RSS from URL destination and parse XML.
=>
1. Get url from RSS (for example, RSS RSS 2.0 Atom)
Parse 2.xmel.

What do you want advice on?

I am wondering if the above method of の can be realized, but I can only get text and images from でも only the URL with RSS information defined.

Twitter and other services also look at the function of retrieving text and images from URLs, but how do you implement them?

I'd like some advice.

swift ruby-on-rails objective-c

2022-09-29 21:58

1 Answers

Indicates how to run on the server side.

You can specify the images that Twitter retrieves as meta information.

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Share Title"/>
<meta name="twitter:description" content="Description of page to share"/>
<meta name="twitter: image" content="https://asset.example.com/images/0h13mQN1VzeOAHNFRFinsA.jpg"/>

Twitter tweets are also the first img tag found in the body tag without the above meta information
You may have obtained it with rules such as .

In that case, you can do it with a gem called Nokogiri.

 html=Nokogiri::HTML(open('http://www.nokogiri.org/tutorials/installing_nokogiri.html'))
first_image=html.css('img').first
image_url=first_image.attributes['src'].try(:value) if first_image

If iOS (swift?) also has a library that can be scraped by URL, you may not need to implement it on the server side.


2022-09-29 21:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.