Coder Social home page Coder Social logo

Comments (5)

d-ivashchuk avatar d-ivashchuk commented on June 22, 2024 1

How I solved this issue: just grabbed the body of the page with axios and with regex found the normal url which then can be processed by ogs. This is a good example of middleware function.

from opengraphscraper.

hamedb89 avatar hamedb89 commented on June 22, 2024 1

@d-ivashchuk Great idea Dimitri, I will try it out as soon as I can get to it. Great idea though thanks!

from opengraphscraper.

d-ivashchuk avatar d-ivashchuk commented on June 22, 2024

Experiencing the same issue! Probably because as already pointed out itโ€™s a mirrored link and not the final link.

@hamedb89 Were you able to solve it?

I would appreciate clarification for this one, as I saw that it should work with redirects, however medium is for sure not working!

Thanks a lot๐Ÿ™Œ๐Ÿผ

from opengraphscraper.

jshemas avatar jshemas commented on June 22, 2024

Hello,

I started digging into this. openGraphScraper uses the request library to make http requests and one of the options that I use is followAllRedirects, which should follow all of the redirects.

request docs: https://github.com/request/request#requestoptions-callback

Unfortunately this is the page I get when using request:

<html>
        <body>
                <script type="text/javascript">
                function unescapeHtml(escaped_str) {
                    var div = document.createElement('div');
                    div.innerHTML = escaped_str;
                    var child = div.childNodes[0];
                    return child ? child.nodeValue : null;
                }

                function validateProtocol(url) {
                        var parser = document.createElement('a');
                    parser.href = url;
                    var protocol = parser.protocol.toLowerCase();
                        if ([ 'javascript:',  'vbscript:',  'data:', 'ftp:',':' , ' '].indexOf(protocol) < 0) {
                                return url;
                        }
                        return null;
                }

                function validate(url) {
                        var unescaped_value = unescapeHtml(url);
                        if (unescaped_value && validateProtocol(unescaped_value)) {
                                return unescaped_value;
                        }
                        return '/';
                }                       var hasURI = false;
                        var intervalExecuted = false;
                        window.onload = function() {
                                document.getElementById("l").src = validate("null/p/17dc61071ed5?link_click_id=656998272080551846");
                                window.setTimeout(function() {
                                        if (!hasURI) {
                                                window.top.location = validate("https://medium.com/@racheltho/techs-long-hours-are-discriminatory-counter-productive-17dc61071ed5?source=linkShare-5037b396cb47-1550350532&amp;_branch_match_id=656998272080551846");
                                        }
                                        intervalExecuted = true;
                                }, 300);
                        };

                        window.onblur = function() {
                                hasURI = true;
                        };

                        window.onfocus = function() {
                                if (hasURI) {
                                        window.top.location = validate("https://medium.com/@racheltho/techs-long-hours-are-discriminatory-counter-productive-17dc61071ed5?source=linkShare-5037b396cb47-1550350532&amp;_branch_match_id=656998272080551846");
                                } else if(intervalExecuted) {
                                        window.top.location = validate("https://medium.com/@racheltho/techs-long-hours-are-discriminatory-counter-productive-17dc61071ed5?source=linkShare-5037b396cb47-1550350532&amp;_branch_match_id=656998272080551846");
                                }
                        }
                </script>
                <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
        </body>
</html>

Request can't run javascript, so there is no way of getting to the final page. To get this to work I would have to rewrite openGraphScraper to use headless chrome or something like that.

from opengraphscraper.

jshemas avatar jshemas commented on June 22, 2024

Yes, using the html option in ogs is great way to solve this problem. Closing the issue.

from opengraphscraper.

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.