-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_script.py
More file actions
40 lines (33 loc) · 1.21 KB
/
test_script.py
File metadata and controls
40 lines (33 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import logging
import json
from configparser import ConfigParser
from playwright.sync_api import sync_playwright
import constants
from post_utils import scrape_single_post_data
# Setup logging
logger = logging.getLogger()
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
# Load config
config = ConfigParser()
config.read('config.ini')
# Test URL (corrected to use threads.net instead of threads.com)
test_url = 'https://www.threads.net/@shygirlmoney/post/DDIWjdeSfyz?xmt=AQF0S7clUBWbZI55Oa1IhNIesFRIZRK0KeAr65S15AuD2g'
# Run the test
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
context = browser.new_context()
page = context.new_page()
# Scrape the post
result = scrape_single_post_data(page, test_url, config, logger, constants)
# Print the result
if result:
print("\n\nRESULT:\n" + json.dumps(result, indent=2, ensure_ascii=False))
print(f"\nImage URLs: {result.get('image_urls', [])}")
else:
print("Failed to scrape the post.")
# Close the browser
browser.close()