Fetch the repository succeeded.
This action will force synchronization from Aron/YTTHpplePlus, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
YTTHpplePlus 是Hpple的扩展,在Hpple的基础上扩展了 HTML/XML文档 节点的增删改查、文档导出功能,原始的Hpple库可以从 Hpple在GitHub上的链接 中查看,感谢作者原始的贡献。
pod 'YTTHpplePlus'
#####对应功能的使用方法参考单元测试类NewPageTest
中找到,支持的功能如下:
- (void)testSetAttr {
NSArray *imgs = [self.doc searchWithXPathQuery:@"//img"];
for (TFHppleElement* element in imgs) {
NSString* raw = element.raw;
NSString* tagName = element.tagName;
NSString* content = element.content;
NSDictionary* attributes = element.attributes;
NSString* src = [element objectForKey:@"src"];
}
// 设置第一个元素的属性
if (imgs.count > 0) {
TFHppleElement* element = imgs.firstObject;
[self.doc setOrUpdateAttribute:@{@"width": @"13131"} inElement:element];
}
[self.doc exportXmlDoc];
NSLog(@"=");
}
<p>
,<a>
,<div>
等标签中的内容- (void)testSetContent {
NSArray *paragraphes = [self.doc searchWithXPathQuery:@"//p"];
if (paragraphes.count) {
TFHppleElement* element = paragraphes.firstObject;
[self.doc setOrUpdateContent:@"这个是更新替换后的内容" inElement:element];
}
[self.doc exportXmlDoc];
}
- (void)testRemoveNode {
NSArray *paragraphes = [self.doc searchWithXPathQuery:@"//p"];
if (paragraphes.count) {
TFHppleElement* element = paragraphes.firstObject;
[self.doc deleteElement:element];
}
[self.doc exportXmlDoc];
}
// 增删改查操作
NSString* exportedHtmlStr = [self.doc exportXmlDoc];
#####TODOS
<script>
标签,这导致了web浏览器加载HTML文档出问题,目前项目中我使用了两种方法解决这个问题,希望有人如果有更好的方案,可以分享一下。script
标签 NSRegularExpression *regularExpression = [NSRegularExpression regularExpressionWithPattern:@"<script.*</script>" options:0 error:nil];
content = [regularExpression stringByReplacingMatchesInString:content options:0 range:NSMakeRange(0, content.length) withTemplate:@""];
script
标签中添加一些额外的内容,然后最终生成文档的时候再进行替换<script src="../js/news-script.js">var abcd;</script>
htmlString = [htmlString stringByReplacingOccurrencesOfString:@"<![CDATA[var abcd;]]>" withString:@""];
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。