Load Instagram JS file and find query hash code :param browser: webdriver instance :param logger: the logger instance :param edge_followed_by: query hash flag, edge_followed_by or edge_follow :return: query hash
(browser, logger, edge_followed_by)
| 2551 | |
| 2552 | |
| 2553 | def get_query_hash(browser, logger, edge_followed_by): |
| 2554 | """ |
| 2555 | Load Instagram JS file and find query hash code |
| 2556 | |
| 2557 | :param browser: webdriver instance |
| 2558 | :param logger: the logger instance |
| 2559 | :param edge_followed_by: query hash flag, edge_followed_by or edge_follow |
| 2560 | :return: query hash |
| 2561 | """ |
| 2562 | link = "https://www.instagram.com/static/bundles/es6/Consumer.js/1f67555edbd3.js" |
| 2563 | web_address_navigator(browser, link) |
| 2564 | page_source = browser.page_source |
| 2565 | # There are two query hash, one for followers and following, ie: |
| 2566 | # t="c76146de99bb02f6415203be841dd25a",n="d04b0a864b4b54837c0d870b0e77e076" |
| 2567 | if edge_followed_by: |
| 2568 | pattern_hash = '[a-z0-9]{32}(?=",n=")' # Used to query: edge_followed_by |
| 2569 | else: |
| 2570 | pattern_hash = '[a-z0-9]{32}(?=",u=1)' # Used to query: edge_follow |
| 2571 | # locate pattern value from JS file |
| 2572 | # sequence of 32 words and/or numbers just before ,n=" value |
| 2573 | hash = re.findall(pattern_hash, page_source) |
| 2574 | if hash: |
| 2575 | return hash[0] |
| 2576 | else: |
| 2577 | logger.warning("Query Hash not found") |
| 2578 | |
| 2579 | |
| 2580 | def file_handling(file): |
no test coverage detected