简体   繁体   中英

Can't get HTML from URL that has google script at bottom?

https://www.pickleballtournaments.com/oncourts.pl?tid=2027&venue=Main

you can view that source and see a near bottom...

Was able to get html before now there is a google script near the bottom and htmlString is now nil. Anyone can get this html? of course gets html for other sites! so the is the blocking issue here! hope we can get the html again please and thank you. Mike

'/table>

'script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script',' https://www.google-analytics.com/analytics.js ','ga');ga('create', 'UA-82207385-1', 'auto');ga('send', 'pageview');

override func viewDidLoad() {
    super.viewDidLoad()

    var url = URL(string: "https://www.pickleballtournaments.com/oncourts.pl?tid=2027&venue=Main")

    let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in

        if error != nil {
            print(error)

        } else {
            let htmlContent = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)

            print("28 htmlContent: \(htmlContent)")
        }
    }

    task.resume()

28 htmlContent: nil

works great gets data with that line in the html content!

override func viewDidLoad() {
    super.viewDidLoad()

    var url = URL(string: "https://www.pickleballtournaments.com/oncourts.pl?tid=2027&venue=Main")

    let task = URLSession.shared.dataTask(with: url!) { (data, response, error) in

        if error != nil {
            print(error)

        } else {
            let htmlContent = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)

            let data = data?.html2String

            print("28 data: \(data)"
        }
    }
    task.resume()   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM