Skip to content

Commit fadb999

Browse files
authored
added contacts and leads, example (#31)
* added contacts and leads, example * bump version to 5.9.3; fix link for api docs
1 parent 3707361 commit fadb999

File tree

4 files changed

+91
-6
lines changed

4 files changed

+91
-6
lines changed

examples/Contacts And Leads.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Emails And Contacts Scraper With Python
2+
3+
Allows finding email addresses, social links, and phones from domains via [Outscraper API](https://app.outscraper.cloud/api-docs#tag/Email-Related/paths/~1contacts-and-leads/get).
4+
5+
## Installation
6+
7+
Python 3+
8+
```bash
9+
pip install outscraper
10+
```
11+
12+
[Link to the Python package page](https://pypi.org/project/outscraper/)
13+
14+
## Initialization
15+
```python
16+
from outscraper import ApiClient
17+
18+
client = ApiClient(api_key='SECRET_API_KEY')
19+
```
20+
[Link to the profile page to create the API key](https://app.outscraper.cloud/profile)
21+
22+
## Usage
23+
24+
```python
25+
# Search contacts from website:
26+
results = client.contacts_and_leads(['outscraper.com'])
27+
```

examples/Enrichments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Using Enrichments Python
22

3-
Using enrichments with [Outscraper API](https://app.outscraper.com/api-docs).
3+
Using enrichments with [Outscraper API](https://app.outscraper.cloud/api-docs).
44

55
## Installation
66

outscraper/api_client.py

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import requests
22
from time import sleep
3-
from typing import Union, Tuple
3+
from typing import Union, Tuple, Optional
44

55
from .utils import as_list, parse_fields, format_direction_queries
66

@@ -9,9 +9,9 @@ class ApiClient(object):
99
'''Outscraper ApiClient - Python SDK that allows using Outscraper's services and Outscraper's API.
1010
```python
1111
from outscraper import ApiClient
12-
cliet = ApiClient(api_key='SECRET_API_KEY')
13-
maps_results = cliet.google_maps_search('restaurants brooklyn usa')
14-
search_results = cliet.google_search('bitcoin')
12+
client = ApiClient(api_key='SECRET_API_KEY')
13+
maps_results = client.google_maps_search('restaurants brooklyn usa')
14+
search_results = client.google_search('bitcoin')
1515
```
1616
https://github.com/outscraper/outscraper-python
1717
'''
@@ -539,6 +539,64 @@ def google_play_reviews(self, query: Union[list, str], reviews_limit: int = 100,
539539

540540
return self._handle_response(response, wait_async, async_request)
541541

542+
def contacts_and_leads(self, query: Union[list, str], fields: Union[list, str] = None, async_request: bool = True,
543+
preferred_contacts: Optional[Union[list, str]] = None, contacts_per_company: int = 3, emails_per_contact: int = 1,
544+
general_emails: bool = False, ui: bool = False, webhook: Optional[str] = None) -> list:
545+
'''
546+
Contacts and Leads Scraper
547+
548+
Returns emails, social links, phones, and other contacts from websites based on domain names, URLs.
549+
It supports batching by sending arrays with up to 250 queries.
550+
It allows multiple queries to be sent in one request and to save on network latency time.
551+
552+
Parameters:
553+
query (list | str): Company domains, URLs (e.g., 'outscraper.com', ['tesla.com', 'microsoft.com']).
554+
fields (list | str): Defines which fields to include in each returned item.
555+
By default, all fields are returned.
556+
async_request (bool): The parameter defines the way you want to submit your task. It can be set to `False`
557+
to open an HTTP connection and keep it open until you got your results, or `True` (default)
558+
to just submit your requests to Outscraper and retrieve them later with the Request Results endpoint.
559+
Default: True.
560+
preferred_contacts (list | str): Contact roles you want to prioritize
561+
(e.g., 'influencers', 'technical', ['decision makers', 'sales']).
562+
Default: None.
563+
contacts_per_company (int): The parameter specifies the number of Contacts per one company.
564+
Default: 3.
565+
emails_per_contact (int): The parameter specifies the number of email addresses per one contact.
566+
Default: 1.
567+
general_emails (bool): The parameter specifies whether to include only general email (info@, support@, etc.)
568+
or only not general email (paul@, john@, etc.).
569+
Default: False.
570+
ui (bool): Execute as a UI task. Overrides async_request to True.
571+
Default: False.
572+
webhook (str): URL for callback notifications when a task completes.
573+
Default: None.
574+
575+
Returns:
576+
list|dict: JSON result
577+
578+
See: https://app.outscraper.cloud/api-docs#tag/Email-Related/paths/~1contacts-and-leads/get
579+
'''
580+
queries = as_list(query)
581+
wait_async = async_request or len(queries) > 1
582+
583+
response = requests.get(f'{self._api_url}/contacts-and-leads', params={
584+
'query': queries,
585+
'fields': parse_fields(fields),
586+
'async': wait_async,
587+
'preferred_contacts': as_list(preferred_contacts) if preferred_contacts else None,
588+
'contacts_per_company': contacts_per_company,
589+
'emails_per_contact': emails_per_contact,
590+
'general_emails': general_emails,
591+
'ui': ui,
592+
'webhook': webhook
593+
}, headers=self._api_headers)
594+
595+
if 199 < response.status_code < 300:
596+
return self._wait_request_archive(response.json()['id']).get('data', [])
597+
598+
raise Exception(f'Response status code: {response.status_code}')
599+
542600
def emails_and_contacts(self, query: Union[list, str], fields: Union[list, str] = None) -> list:
543601
'''
544602
Return email addresses, social links and phones from domains in seconds.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name='outscraper',
11-
version='5.9.2',
11+
version='5.9.3',
1212
description='Python bindings for the Outscraper API',
1313
long_description=readme(),
1414
classifiers = ['Programming Language :: Python',

0 commit comments

Comments
 (0)