Skip to main content

Unofficial api of Divar(Scrapping Divar)

Project description

DivarApi 🇮🇷

English / فارسی - Farsi

Developed by V1Z/Palas - 2024

1. Setup and Instalation

pip3 install divar

Usage

Divar lib support both async and sync programming so youre free to use which one you like

from divar import Client # its async client.
from divar import sync_client # its sync client as its name seggests!

AsyncDivarBot = Client()
SyncDivarBot = sync_client()

Getting Category posts ( Agahi ha )

For that you just to need to call GetCategory method on your client object. Example :

#async version be like :
await AsyncDivarBot.GetCategory('CityName', 'Category-Name' , *args , *kwargs)

#sync version be like :
SyncDivarBot.GetCategory('CityName', 'Category-Name' , *args , *kwargs)

Searching in posts ( New Feature )

Its new feature added to lib for your requests and support <3 as method above i saied you need to call it from the client instance. pass the query and also you can pass city codes to get more accurate posts from your city

Examples:

#async version without cities specified returns posts all over IRAN 
await AsyncDivarBot.Search(query = 'iPhone 13')

#async version but cities specified > code hints : mashhad -> 3 , tehran -> 1 , isfahan -> 4
await AsyncDivarBot.Search(query = 'iPhone 13' , cities = [1,3,4])

#<-------------------------Sync version-------------------------/>
#sync version without cities specified returns posts all over IRAN 
syncDivarBot.Search(query = 'iPhone 13')

#sync version but cities specified > code hints : mashhad -> 3 , tehran -> 1 , isfahan -> 4
syncDivarBot.Search(query = 'iPhone 13' , cities = [1,3,4])

Getting post info

Every post in Divar.ir has a Unique identifier named as Token. you can find them at the end of url bar of a post or in methods below.

with GetPost method you can get info about the post like : -Images -Location -Price -Description and etc.

#<---------------------------Async Version-------------------------/>
await AsyncDivarBot.GetPost('Token')

#<---------------------------sync Version-------------------------/>
SyncDivarBot.GetPost('Token')

Authentication (Login/Sign-Up)

Its new Feature implented abvisouly for your requests.

Authentication is 2 step process , first you need to get otp code to your phone number you can get that with sign method which is not friendly cause can be used for spamming since divar doesnt have anti spam algorithm or preventaion with their message service Second you need to login with that otp code on your phone number which returns a jwt-token to work with special methods (login needed) like GetNumber , you can do the second one with login method which needs your phone number and otp code.

Example:

#<---------------------------Async Version-------------------------/>
await AsyncDivarBot.sign('0987654321') # send otp code (6digits) to the number if returns True else Flase.

#Now you need to login with the otp code (if login successful youre free to use special methods i said above)
await AsyncDivarBot.login('0987654321' , '123456')

#<---------------------------Sync Version-------------------------/>
syncDivarBot.sign('0987654321') # send otp code (6digits) to the number if returns True else Flase.

#Now you need to login with the otp code (if login successful youre free to use special methods i said above)
syncDivarBot.login('0987654321' , '123456')

Getting Number of a post

Its login required method so if you didnt login with above method it will ask for your number and your otp code and itll login you if youre not , pass the Token of post as first arg.

#<---------------------------Async Version-------------------------/>
await AsyncDivarBot.GetNumber('PostToken')

#<---------------------------Sync Version-------------------------/>
syncDuvarBot.GetNumber('PostToken')

New Feature Comming in v2.5:

Divar Chat

Map specifing

and more...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

divar-2.0.1.tar.gz (11.6 kB view hashes)

Uploaded Source

Built Distribution

divar-2.0.1-py3-none-any.whl (15.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page