ๅฃ“ๅ€’
Ye0L
ๅฃ“ๅ€’
Total
Home
Today
  • ByO (59)
    • ์•…์„ฑ์ฝ”๋“œ๋ถ„์„๐Ÿณ (10)
      • Android (2)
      • Windows (8)
    • ๋ฐฑ์ค€โŒจ (1)
    • ๊ฐœ๋ฐœ๐Ÿ’ป (14)
      • Python (14)
      • C (0)
    • AI (2)
      • ML (2)
      • DL (0)
    • Dreamhack (23)
      • Web hacking (20)
      • Reversing (3)
    • CTF (5)
      • Forensic (5)
    • Study (4)
      • Linux (2)
      • Web (2)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ๋ฐฉ๋ช…๋ก
  • ๊นƒํ—ˆ๋ธŒ๐Ÿ˜€
  • ํ‹ฐ์Šคํ† ๋ฆฌ ํ™ˆ

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • Raccoon Stealer v2
  • Raccoon Stealer
  • ClientSide: XSS
  • web hacking
  • File Download Vulnerability
  • ๋ฆฌ๋ฒ„์‹ฑ
  • APK ๊ตฌ์กฐ
  • reversing
  • forensic
  • Background: Cookie & Session
  • ํฌ๋กค๋ง
  • selenium
  • Crawling
  • dreamhack
  • ์•…์„ฑ์ฝ”๋“œ๋ถ„์„
  • [DigitalForensic]with CTF
  • Background:Web Browser
  • CSRF
  • ๋“œ๋ฆผํ•ต
  • PYTHON

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
ๅฃ“ๅ€’

Ye0L

[Python] Selenium์„ ์‚ฌ์šฉํ•œ ํฌ๋กค๋ง ์ œ์ž‘(1)
๊ฐœ๋ฐœ๐Ÿ’ป/Python

[Python] Selenium์„ ์‚ฌ์šฉํ•œ ํฌ๋กค๋ง ์ œ์ž‘(1)

2022. 9. 7. 22:08

Install

์ผ๋ฐ˜์ ์ธ ์„ค์น˜๊ณผ์ •๊ณผ ๋™์ผํ•˜๊ฒŒ "pip install selenium"์„ ์‚ฌ์šฉํ•˜์—ฌ ์„ค์น˜ํ•  ์ˆ˜ ์žˆ๋‹ค.

Import

import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

Code

"๋ด‡์ด ์•„๋‹ˆ๋ผ ์‚ฌ๋žŒ์ด์•ผ"๋ฅผ ์•Œ๋ ค์ฃผ๊ธฐ ์œ„ํ•ด user_agent๋ฅผ ์ถ”๊ฐ€ํ•œ ํ›„ webdriver ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

(webdriver๋ฅผ ๋™์ผ ๊ฒฝ๋กœ ๋‚ด์— ์œ„์น˜์‹œ์ผœ ๋ณ„๋„์˜ ๊ฒฝ๋กœ ์ง€์ • ์ฝ”๋“œ๋Š” ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์•˜๋‹ค.)

user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
options.add_argument('user-agent=' + user_agent)
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option('prefs', {
    "download.default_directory": r"๋‹ค์šด๋กœ๋“œ ๋Œ€์ƒ ๊ฒฝ๋กœ ์ง€์ •",
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "safebrowsing.enabled": True})
driver = webdriver.Chrome(options=options)

 

์ƒ์„ฑํ•œ driver ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ URL์— ์ ‘์†ํ•œ๋‹ค.

url1 = '๋Œ€์ƒ URL'
driver.get(url1)
time.sleep(1)

 

ํŠน์ • ๋ฒ„ํŠผ ํด๋ฆญ, ํƒœ๊ทธ ๋‚ด ์กด์žฌํ•˜๋Š” ๊ฐ’ ํŒŒ์‹ฑ๊ณผ ๊ฐ™์€ ๋™์ž‘์€ Selenium ๋‚ด ์กด์žฌํ•˜๋Š” Xpath, CSS_Selector๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•˜์˜€๋‹ค. 

Xpath ์™€ CSS_Selector์€ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ์—์„œ ์šฐ์ธก ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ฒŒ ๋˜๋ฉด ์‰ฝ๊ฒŒ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

Xpath, selector

Selenium์„ ์‚ฌ์šฉํ•˜์—ฌ ํฌ๋กค๋ง์„ ์ œ์ž‘ํ•  ๋•Œ Xpath, Selector ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ์ผ์น˜ํ•˜๋Š” ํŒจํ„ด์„ ํ™•์ธํ•œ๋‹ค. ํ•ด๋‹น ํฌ๋กค๋ง์—์„œ๋„ ์ผ์ •ํ•œ ํŒจํ„ด์ด ํ™•์ธ๋˜์–ด Format ์„ ์‚ฌ์šฉํ•˜์—ฌ ์‰ฝ๊ฒŒ ์ œ์ž‘ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค. 


๋Œ€๋žต์ ์ธ ์†Œ์Šค์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์œผ๋ฉฐ ์†Œ์Šค์ฝ”๋“œ ์ „์ฒด๋Š” ๊นƒํ—ˆ๋ธŒ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

https://github.com/byeongyeolahn/Bazaar_Mobile_malware_crawling

import requests
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

options = Options()

# ์˜ต์…˜ ์„ค์ •
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36'
options.add_argument('user-agent=' + user_agent)
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option('prefs', {
    "download.default_directory": r"๋‹ค์šด๋กœ๋“œ ๋Œ€์ƒ ๊ฒฝ๋กœ ์ง€์ •",
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "safebrowsing.enabled": True})
driver = webdriver.Chrome(options=options)

# ์ดˆ๊ธฐ ๊ฒ€์ƒ‰์–ด ์ž…๋ ฅ
query = '๊ฒ€์ƒ‰์–ด'

# URL ์ ‘์†
url1 = '๋Œ€์ƒ URL'
driver.get(url1)
time.sleep(1)

# apk ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ ํ™”๋ฉด
driver.find_element(By.XPATH, '/html/body/main/div[1]/div/p[2]/a').click()
search_tab = driver.find_element(By.CSS_SELECTOR, '#search')
search_tab.send_keys(query)
search_tab.send_keys(Keys.ENTER)
time.sleep(3)

# apk ํŒŒ์ผ๋“ค sha256 ๊ฐ’ ๋ชจ์œผ๊ธฐ
file_hash = []
# for i in range(1,4):
for k in range(2,6):
    driver.find_element(By.XPATH, '//*[@id="samples_paginate"]/ul/li[{}]/a'.format(k)).click()
    for i in range(1,251):
        tag_td = driver.find_element(By.CSS_SELECTOR, '#samples > tbody > tr:nth-child({}) > td:nth-child(2) > a'.format(i))
        tag_href = tag_td.get_attribute('href')
        file_hash.append(tag_href)

# ์ดํ›„ ๊นƒํ—ˆ๋ธŒ(https://github.com/byeongyeolahn/Bazaar_Mobile_malware_crawling) ๊ฒŒ์‹œ

 

 

์˜ค๋ฅ˜, ์ž˜๋ชป๋œ ์  ๋˜๋Š” ๊ถ๊ธˆํ•œ ์ ์ด ์žˆ์œผ์‹œ๋‹ค๋ฉด ๋Œ“๊ธ€ ๋‚จ๊ฒจ์ฃผ์„ธ์š”โ—

'๊ฐœ๋ฐœ๐Ÿ’ป > Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Python] ZipํŒŒ์ผ ์••์ถ• ํ•ด์ œ(2)(๋น„๋ฐ€๋ฒˆํ˜ธ ํฌํ•จ)  (0) 2022.10.04
[Python] Selenium์„ ์‚ฌ์šฉํ•œ ํฌ๋กค๋ง ์ œ์ž‘(2)  (0) 2022.09.30
[Python] pymysql ์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๊ฐ’(Tuple)์„ List๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๋ฒ•  (0) 2022.09.27
[Python] ZipํŒŒ์ผ ์••์ถ• ํ•ด์ œ(1)(๋น„๋ฐ€๋ฒˆํ˜ธ ํฌํ•จ)  (0) 2022.09.17
[Python] Selenium ์‚ฌ์šฉํ•˜๊ธฐ  (0) 2022.09.09
    '๊ฐœ๋ฐœ๐Ÿ’ป/Python' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [Python] Selenium์„ ์‚ฌ์šฉํ•œ ํฌ๋กค๋ง ์ œ์ž‘(2)
    • [Python] pymysql ์„ ํ†ตํ•ด ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค ๊ฐ’(Tuple)์„ List๋กœ ๊ฐ€์ ธ์˜ค๋Š” ๋ฒ•
    • [Python] ZipํŒŒ์ผ ์••์ถ• ํ•ด์ œ(1)(๋น„๋ฐ€๋ฒˆํ˜ธ ํฌํ•จ)
    • [Python] Selenium ์‚ฌ์šฉํ•˜๊ธฐ
    ๅฃ“ๅ€’
    ๅฃ“ๅ€’
    ์•…์„ฑ์ฝ”๋“œ ๋ถ„์„, ๊ฐœ๋ฐœ, ๋ฐฑ์ค€ ๋“ฑ ๋‚˜์˜ ์ผ์ง€

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”