Git Product home page Git Product logo

Comments (5)

mna avatar mna commented on September 26, 2024 2

Hi Evan,

That's because in Go, a function can return multiple values, and that is the case for the Attr() method. It returns the attribute's value (if any), and a boolean indicating if the attribute actually exists on the selection. That's often referred to as the "comma ok" idiom in Go, because you usually call those type of methods like this:

val, ok := MultiReturnFunc()

So in your case, you would write:

mp4, ok := s.Find("video").Attr("src") and you can check ok to make sure the attribute exists, or if you don't care either way, you can discard the second return value using an underscore as variable name (the "blank" identifier, since the compiler will complain if ok is never used).

Have fun!
Martin

from goquery.

evanriley avatar evanriley commented on September 26, 2024

Thanks for the help! and sorry to bug again, but could you look at my code and help me figure out why I'm getting blank returns on my query? Instead of getting the .mp4 link I get nothing and the program stops without an error or anything.

from goquery.

mna avatar mna commented on September 26, 2024

Ah yes, the code is correct, it's just that the whole page is javascript-heavy. If you disable javascript and load the page, you'll see that there's nothing there, so that's what goquery sees.

I've heard of some people that have used goquery with a headless browser to scrape javascript-based webpages, but I haven't tried it myself. I believe it was with this: https://github.com/sourcegraph/webloop

from goquery.

cryptix avatar cryptix commented on September 26, 2024

@eriley in this case you actually don't need a full webkit (cookies and what not). You 'just' need a javascript interpreter (like otto) and evaluate the contents of the first <script> Tag.

This gist has a solution if you want to take a look.

ps: don't fetch them all at once ;)

from goquery.

evanriley avatar evanriley commented on September 26, 2024

Thanks for recommendations 😄 I was able to use use the VineURL and then add /card to it, and it just gives the mp4 in a html5 video player without any hassle. I'll be sure to remember you're recommendations for the future though!

from goquery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.