我正在使用HTMLAgilityPack,而我正在尝试抓取 data-preconnect-urls 下的 http://www.hundsun.co.jp/ 链接。我怎么能得到它?
<h3>
<a style="display:none" href="/aclk?sa=L&ai=DChcSEwimnPnc5OvQAhWRl70KHcxqCEAYABAA&ei=9hZNWLqlCIyY8gXA04vACg&sig=AOD64_3SZuXd57_-qOs8nnhn8rqw8GlIgw&q=&sqi=2&ved=0ahUKEwi6-PTc5OvQAhUMjLwKHcDpAqgQ0QwIGA&adurl=" id="s0p1c0"></a>
<a href="https://www.google.co.jp/aclk?sa=L&ai=DChcSEwimnPnc5OvQAhWRl70KHcxqCEAYABAA&ei=9hZNWLqlCIyY8gXA04vACg&sig=AOD64_3SZuXd57_-qOs8nnhn8rqw8GlIgw&q=&sqi=2&ved=0ahUKEwi6-PTc5OvQAhUMjLwKHcDpAqgQ0QwIGA&adurl=" id="vs0p1c0" onmousedown="return google.arwt(this)" data-preconnect-urls="http://www.hundsun.co.jp/" jsl="$t t-zxXzjt1d4B0;$x 0;" class="r-iA_xzYkgkx2Y">ブリッジSE募集中 - hundsun.co.jp</a>
答案 0 :(得分:1)
你可以这样做:
//
// Play with finding substrings returning an array of the non-unique words and positions in text
//
//
import UIKit
let Bigstring = "Why is it so hard to find substrings in Swift3"
let searchStrs : Array<String>? = ["Why", "substrings", "Swift3"]
FindSubString(inputStr: Bigstring, subStrings: searchStrs)
func FindSubString(inputStr : String, subStrings: Array<String>?) -> Array<(String, Int, Int)> {
var resultArray : Array<(String, Int, Int)> = []
for i: Int in 0...(subStrings?.count)!-1 {
if inputStr.contains((subStrings?[i])!) {
let range: Range<String.Index> = inputStr.range(of: subStrings![i])!
let lPos = inputStr.distance(from: inputStr.startIndex, to: range.lowerBound)
let uPos = inputStr.distance(from: inputStr.startIndex, to: range.upperBound)
let element = ((subStrings?[i])! as String, lPos, uPos)
resultArray.append(element)
}
}
for words in resultArray {
print(words)
}
return resultArray
}
你可以在这里试试: