我正在尝试使用Selenium:https://results.decisiondeskhq.com/2020/primary/colorado/president抓取该网站(如果您想检查元素,则必须快速注册一个帐户才能看到我要抓取的表格)。对于不同的元素(候选,投票,Pct)似乎没有任何一致的属性。我该怎么刮呢?
表格的HTML:
Word2Vec.load()
到目前为止,我的代码:
import UIKit
class MyViewController: UIViewController {
let myButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
override init(nibName nibNameOrNil: NSNib.Name?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
// without parameter style
let action = #selector(MyViewController.tappedButton)
// with parameter style
// #selector(MyViewController.tappedButton(_:))
myButton.addTarget(self, action: action, forControlEvents: .touchUpInside)
}
@objc func tappedButton(_ sender: UIButton?) {
print("tapped button")
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
}
提前谢谢!
答案 0 :(得分:0)
您可以在xpath下面使用它来处理表中的元素。根据您的要求,您可以使用xpath并处理数据。
检索所有tr和td
var tasks = y.Select(x => MyCustomTask(x)).ToList();
await Task.WhenAll(tasks);
检索第一行
//div[@class='top-line-table']//tbody//tr[*]/td
检索第一列
//div[@class='top-line-table']//tbody//tr[1]/td
处理广告
//div[@class='top-line-table']//tbody//td[1]