Should I use Regx, embed jQuery or HTML analysis in a WebView to get its contents?

Accepting creteria-ish I have a website (not mine) that I display in WebView. Based on the content of the page, I would like to suggest my own click on the button (the button is not a problem).

What you need to do I need to check if the HTML content contains 2-3 specific URLs. URL can be 2-3 places on the page. If there are no URLs (sometimes they are, sometimes they do not fit), I need to do another content search to create the URL that I'm going to launch.

Possible solutions

  • Screen screening with Objective-C -HMTL-Parser, HPPLE, ElemetParser, XPathQuery with libxml2 for HTML analysis and content search. Prons : Easy Cons : You need well-formed HTML / XML. Probably slow for many concurrent tree searches.
  • Use regex. Prons :? Cons Difficult to read / write fast. We need well-formed HTML / XML. Probably slow for many concurrent searches. (Did not try RegexKit Light).
  • Insert jQuery search functions into WebView and call functions from Objective-c. WebViewJavascriptBridge looks promising for use in betweean Js and ObjC (also looked at TGJSBridge, GAJavaScript and iOS-JavaScript-Bridge Prons : easily insert JQuery into WebViewJavascriptBridge code and invoke it using dele Cons : bulky.
  • Is there any other solution that I skipped?

I am inclined to the decision nr. 3. using WebViewJavascriptBridge , where I would introduce jQuery search functions in a handler that will be called when it finds something. Can I run this search in multiple threads or do a tree search and find all my search items?

Summary

-1. What is the β€œbest” / quick fix looking for (multi-user) content on the Internet that is not yours?

-2. Is there another solution I missed?

-3. Is it possible to run multiple jQuery searches in a thread, returning the results back to Objc every time something is found?

+4
source share
1 answer

Answering your question # 2 (any other methods that you skipped):

You can do the parsing and everything else, but just to find out if the HTML content contains specific URLs, will the NSString rangeOfString method be enough? It depends on the formatting of the course URL and what you need (search only for any mention of the URL? Mention of the URL inside a specific tag? Can the URL appear in another place that should not be considered?).

But from your question, I realized that the task is a bit more complicated, so you could provide an html fragment, perhaps?

0
source

Source: https://habr.com/ru/post/1440314/


All Articles