iabudiab / HTMLKit

An Objective-C framework for your everyday HTML needs.
MIT License
239 stars 27 forks source link

Master #26

Closed samhuangszu closed 6 years ago

samhuangszu commented 6 years ago

can suport this css selector [property=og:url]? url: http://www.87wx.net/book/88577/

codecov[bot] commented 6 years ago

Codecov Report

Merging #26 into develop will decrease coverage by 0.53%. The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop      #26      +/-   ##
===========================================
- Coverage    92.33%   91.79%   -0.54%     
===========================================
  Files           54       73      +19     
  Lines         6574     7278     +704     
  Branches      1160     1160              
===========================================
+ Hits          6070     6681     +611     
- Misses         493      597     +104     
+ Partials        11        0      -11
Impacted Files Coverage Δ
Sources/HTMLEOFToken.m 85.71% <0%> (-5.2%) :arrow_down:
Sources/CSSCombinatorSelector.m 82.22% <0%> (-4.45%) :arrow_down:
Sources/CSSSelector.m 35.71% <0%> (-4.29%) :arrow_down:
Sources/HTMLListOfActiveFormattingElements.m 86.88% <0%> (-3.36%) :arrow_down:
Sources/CSSTypeSelector.m 85.71% <0%> (-3.18%) :arrow_down:
Sources/CSSPseudoClassSelector.m 84.61% <0%> (-2.89%) :arrow_down:
Sources/HTMLDOMTokenList.m 79.54% <0%> (-1.71%) :arrow_down:
Sources/HTMLText.m 92.3% <0%> (-1.64%) :arrow_down:
Sources/HTMLCommentToken.m 70% <0%> (-1.43%) :arrow_down:
Sources/CSSCompoundSelector.m 72.41% <0%> (-1.28%) :arrow_down:
... and 54 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update da76516...8546168. Read the comment docs.

iabudiab commented 6 years ago

@samhuangszu Why is this a Pull Request? Did you mean to open a new issue with a feature request?

iabudiab commented 6 years ago

@samhuangszu This selector is already supported.

NSURL *url = [NSURL URLWithString:@"http://www.87wx.net/book/88577/"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

HTMLDocument *doc = [HTMLDocument documentWithString:html];
NSArray<HTMLElement *> *elements = [doc querySelectorAll:@"[property='og:url']"];
for (HTMLElement *element in elements) {
  NSLog(@"%@\n", element[@"content"]);
}

// Output
// http://www.87wx.net/88/88577/
samhuangszu commented 6 years ago

[property=og:url] the selector is some different [property='og:url'], when use [property=og:url] , can't query the target.

iabudiab commented 6 years ago

[property=og:url] the selector is some different [property='og:url'], when use [property=og:url] , can't query the target.

What do you mean by different?

Semantically they are the same, however the [property=og:url] selector wont work because it is, strictly speaking, not a valid CSS selector.

HTMLKit parses CSS3 Selectors according to the specification, more specifically the section about Attribute Selectors. An attribute's value is either a CSS String or a CSS Identifier

You should use a valid selector syntax, which is either:

Let me know if you mean something else. However this PR should be an issue anyway, so closing it here. Please open an issue next time if you're asking for a feature request.