-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCODE 2: Start Account SN Scraper in PB .py
50 lines (44 loc) · 1.67 KB
/
CODE 2: Start Account SN Scraper in PB .py
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
41
42
43
44
45
46
47
48
49
50
import os
import requests
def main(event):
# Extract the required input fields
linkedinCompanyPage = event['inputFields']['linkedin_company_page']
hsObjectId = event['object']['objectId']
# Define the Phantombuster API endpoint, headers, and payload for launch
launch_url = "https://api.phantombuster.com/api/v2/agents/launch"
headers = {
"Content-Type": "application/json",
"X-Phantombuster-Key": os.getenv('PBAPI') # Fetch the API key from environment variable
}
payload = {
"id": "8637067489167032",
"arguments": {
"sessionCookie": os.getenv('PB_SESSION_COOKIE'), # Fetch the session cookie from environment variable
"spreadsheetUrl": linkedinCompanyPage
},
"manualLaunch": False
}
# Print out the payload for debugging
print("Payload:", payload)
try:
# Send POST request to Phantombuster for launch
response = requests.post(launch_url, json=payload, headers=headers)
# Check for a successful response and extract the containerId
if response.status_code == 200:
response_data = response.json()
if 'containerId' in response_data:
return {
"outputFields": {
"containerId": response_data['containerId'],
"hs_object_id": hsObjectId
}
}
else:
raise ValueError('Unexpected response from Phantombuster: No containerId.')
else:
response.raise_for_status()
except Exception as e:
print('Error:', e)
return {
"outputFields": {}
}