• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to get hyperlink in a html file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get hyperlink in a html file?


  • Subject: Re: How to get hyperlink in a html file?
  • From: Leo <email@hidden>
  • Date: Thu, 19 Oct 2006 09:32:54 +0800

Thanks Mike and John, but can you give me some details to do this? maybe i can get the URL with using NSScaner, but how to get the string between '<a href=...>xxxx</a>'? usually there is some other html tag inside <a >tag, such as '<a herf=...><font color><b>xxxx</b></font></a>', how scan it?

by the way, does anybody know how to use stringWithContentsOfFile: usedEncoding: error: i want use it to get the content of html file, but how to detect the encoding? when i try it like this:

NSString *stringFromFileAtPath=[NSString stringWithContentsOfFile:filePath usedEncoding:NSUTF8StringEncoding error:&error];

the Xcode displays after build:" warning: passing argument 2 of stringWithContentsOfFile: usedEncoding: error: makes pointer from integer without a cast"

but no warning when using stringWithContentsOfFile: encoding: error:

both of these 2 methods can't open some Chinese and Japanese HTML file.

anybody can tell me how to detect the encoding in order to get the content of html?

thank you very much.

Leo

John Stiles wrote:
I think the only way to do this and have it work with arbitrary web pages is to parse the DOM and look for links that way.
You can't cleanly scan for text given an arbitrary HTML file, since JavaScript is able to modify the DOM structure at will (or even document.write in a whole new section of the page!). Using JavaScript to construct a complicated page is not too uncommon.
I don't know if WebKit provides the tools to analyze the DOM from inside Obj-C. If not, you may have to use JavaScript :(


Mike Abdullah wrote:
Well you could use NSScanner to scan up to any instances of:

    <a

and then read in the URL from there. Not entirely sure it's the best method though.

Mike.

On 18 Oct 2006, at 04:57, Leo wrote:

Hi to all,

If this is a stupid question, I apologize in advance, though I am pretty
new at this Cocoa stuff.


I try to get the content of a html file, if some of the contents is like
this:


<tr>
<td>
<p><font face="Lucida Grande,Arial, sans-serif"><a
href="../pgs/557.html">About import settings and hard disk
space</a></font></p>
</td>
</tr>
<tr>
<td>
<p><font face="Lucida Grande,Arial, sans-serif"><a
href="../pgs/629.html">About AIFF and WAV custom import
options</a></font></p></td></tr>


how to search the hyperlink string? such as:

get the string "About import settings and hard disk space".

get the string "../pgs/557.html" and convert it to absolute path.

hope someone can help me. thanks.

Leo







_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >How to get hyperlink in a html file? (From: Leo <email@hidden>)
 >Re: How to get hyperlink in a html file? (From: Mike Abdullah <email@hidden>)
 >Re: How to get hyperlink in a html file? (From: John Stiles <email@hidden>)

  • Prev by Date: Re: 'incompatible types in initialization' when using NSTableColumn width float
  • Next by Date: Re: ow to capture Key event in a NSApp
  • Previous by thread: Re: How to get hyperlink in a html file?
  • Next by thread: Capture spacebar
  • Index(es):
    • Date
    • Thread