Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d680646

Browse files
Merge pull request avinashkranjan#2741 from Juhibhojani/master
Telegram Get-Group-Members Bot
2 parents 42fbfe7 + 268eeef commit d680646

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Telegram Web Get-Group-Members Bot
2+
3+
Automate the process of retrieving member information from a Telegram group using this Python script. The script utilizes the Selenium library to interact with Telegram Web and extract member details.
4+
5+
## Installation
6+
7+
1. Ensure you have Python installed on your system.
8+
2. Clone this repository or download the provided code:
9+
10+
```bash
11+
git clone [https://github.com/avinashkranjan/Amazing-Python-Scripts]
12+
```
13+
14+
3. Navigate to the project directory:
15+
16+
```bash
17+
cd Telegram Get-Group-Members Bot/telegram.py
18+
```
19+
4. Install the required dependencies:
20+
21+
```bash
22+
pip install -r requirements.txt
23+
```
24+
5. Download the [ChromeDriver](https://chromedriver.chromium.org/downloads) suitable for your Chrome version and place it in the project directory.
25+
26+
## Usage
27+
28+
1. Make sure you have a compatible version of Chrome installed on your system.
29+
2. Run the script:
30+
31+
```bash
32+
python telegram.py
33+
```
34+
3. A Chrome browser window will open, displaying Telegram Web.
35+
4. Scan the QR code using your phone to log in to Telegram Web.
36+
5. After successful login, the script will wait for 10 seconds to load the page.
37+
6. Enter the name of the group you want to retrieve member information for when prompted.
38+
7. The script will print the member names and images on the terminal.
39+
40+
## Notes
41+
42+
- This script uses the Chrome WebDriver for Selenium automation. Ensure that the `chromedriver` executable matches your Chrome browser version and is located in the project directory.
43+
- The script waits for 10 seconds to ensure proper loading of the Telegram Web page before interaction. You can modify this delay if necessary.
44+
45+
## Contributor
46+
47+
- [Juhi Bhojani](https://github.com/Juhibhojani)
48+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
beautifulsoup4==4.9.3
2+
selenium==3.141.0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from selenium import webdriver
2+
from selenium.webdriver.support.ui import WebDriverWait
3+
from selenium.webdriver.common.by import By
4+
from selenium.webdriver.common.keys import Keys
5+
from bs4 import BeautifulSoup
6+
import time
7+
from selenium.webdriver.support import expected_conditions as EC
8+
9+
# Initialize the Chrome WebDriver
10+
driver = webdriver.Chrome()
11+
12+
# Open the Telegram Web URL
13+
driver.get("https://web.telegram.org/k/")
14+
print("Scan QR Code, And then Enter")
15+
time.sleep(10)
16+
print("Logged In")
17+
18+
# XPath for the search input field
19+
search_input_xpath = "//input[@class='input-field-input i18n input-search-input']"
20+
21+
# Wait for the search input field to be clickable
22+
wait = WebDriverWait(driver, 10)
23+
search_input = wait.until(EC.element_to_be_clickable((By.XPATH, search_input_xpath)))
24+
25+
group_name = input("Enter the group name")
26+
# Perform a search by sending keys and pressing RETURN
27+
search_input.send_keys(group_name)
28+
time.sleep(2)
29+
search_input.send_keys(Keys.RETURN)
30+
31+
# Find and click on a chat from the search results
32+
chat_xpath = "//a[@class='row no-wrap row-with-padding row-clickable hover-effect rp chatlist-chat chatlist-chat-abitbigger']"
33+
chat_element = driver.find_element(By.XPATH, chat_xpath)
34+
time.sleep(2)
35+
chat_element.click()
36+
37+
# Find and click on a group in the chat
38+
person_profile_xpath = "//div[@class='person']"
39+
person_profile_element = driver.find_element(By.XPATH, person_profile_xpath)
40+
time.sleep(2)
41+
person_profile_element.click()
42+
43+
# Get the page source and parse with BeautifulSoup
44+
html = driver.page_source
45+
soup = BeautifulSoup(html, "html.parser")
46+
47+
# Find the container for member information
48+
members_container = soup.find("div", {"class": "search-super-content-members"})
49+
50+
# Iterate through each member and extract information
51+
for member_item in members_container.find("ul"):
52+
member_name = member_item.find("span", {"class": "peer-title"})
53+
if member_name:
54+
print("Member Name:", member_name.text)
55+
56+
member_img = member_item.find("img")
57+
if member_img:
58+
print("Member Image:", member_img['src'])
59+
60+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /