(response)
| 801 | # --- API Interception for raw post data --- |
| 802 | api_data = [] |
| 803 | def handle_response(response): |
| 804 | try: |
| 805 | url = response.url |
| 806 | if any(x in url for x in ["graphql/query", "api/v1/feed", "api/v1/profile", "api/v1/users", "api/v1/media", "api/v1/highlights", "tags", "comments"]): |
| 807 | data = response.json() |
| 808 | api_data.append(data) |
| 809 | |
| 810 | parsed = urllib.parse.urlparse(url) |
| 811 | q = urllib.parse.parse_qs(parsed.query) |
| 812 | qhash = q.get("query_hash", [None])[0] |
| 813 | encoded_variables = (q.get("variables") or [None])[0] |
| 814 | |
| 815 | def _extract_insta_pageinfo(node): |
| 816 | if isinstance(node, dict): |
| 817 | page_info = node.get("page_info") or node.get("pageInfo") |
| 818 | if isinstance(page_info, dict): |
| 819 | has_next = page_info.get("has_next_page") |
| 820 | end_cursor = page_info.get("end_cursor") or page_info.get("endCursor") |
| 821 | if has_next and end_cursor and qhash: |
| 822 | try: |
| 823 | variables = json.loads(encoded_variables) if encoded_variables else {} |
| 824 | except Exception: |
| 825 | variables = {} |
| 826 | if isinstance(variables, dict): |
| 827 | collected_api_pages.append({ |
| 828 | "query_hash": qhash, |
| 829 | "variables": variables, |
| 830 | "end_cursor": str(end_cursor), |
| 831 | "page_info": bool(has_next) |
| 832 | }) |
| 833 | for v in node.values(): |
| 834 | _extract_insta_pageinfo(v) |
| 835 | elif isinstance(node, list): |
| 836 | for it in node: |
| 837 | _extract_insta_pageinfo(it) |
| 838 | |
| 839 | _extract_insta_pageinfo(data) |
| 840 | except: |
| 841 | pass |
| 842 | page.on("response", handle_response) |
| 843 | |
| 844 | page.goto(f"https://www.instagram.com/{target}/", wait_until="domcontentloaded") |
nothing calls this directly
no outgoing calls
no test coverage detected