selenium 아무리 고민해도 모르겠어서 질문드립니다.

bedals의 이미지

# -*- coding: utf-8 -*-
"""
Created on Sun May  5 20:44:38 2019
 
@author: Administrator
"""
# -*- coding: utf-8 -*-
"""
Created on Sun May  5 12:55:16 2019
 
@author: Administrator
"""
 
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time
 
 
num_of_pagedowns = 18# 페이지수
rank = 1 
 
 
 
driver = webdriver.Chrome('C:\chromedriver.exe')
 
driver.get('https://m.naver.com')
 
time.sleep(1)
 
# 처음 로드 해서 변수 A 까지
elem = driver.find_element_by_xpath('//*[@id="t21"]/div/button').click() #팝업창 클릭
elem = driver.find_element_by_xpath('//*[@id="MM_SEARCH_FAKE"]') #검색창 클릭
elem.click()
elem = driver.find_element_by_xpath('//*[@id="query"]')
elem.send_keys('박지성')
elem.send_keys(Keys.ENTER)
time.sleep(1)
 
# 두번째 부터 변수 B까지,쇼핑 더보기 내부 로직 시작
elem = driver.find_element_by_xpath('//*[@id="nx_query"]')
elem.clear()
elem.send_keys('남성청결제')
elem.send_keys(Keys.ENTER)
time.sleep(2)
elem = driver.find_element_by_xpath('//*[@id="ct"]/section[1]/div[2]/a').click()
 
for a in range(0,3):
 
    if a == 0:
 
        body = driver.find_element_by_xpath('/html/body')   
 
        while num_of_pagedowns:
            body.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.5)
            num_of_pagedowns -= 1
 
 
        html  = driver.page_source
        soup =BeautifulSoup(html,'lxml')
        titles = soup.find_all('span', class_='_2rxlO_K3YY')
        for title in titles:
            rank += 1
            if title.get_text()=='신세계몰':
                print(str(rank)+"번째 : "+title.get_text())
                time.sleep(2)
    elif 0 < a:
        body = driver.find_element_by_xpath('/html/body')   
        elem = driver.find_element_by_xpath('//*[@id="content"]/div[5]/a[%d]'%(a+1)).click()
        while num_of_pagedowns:
            body.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.5)
            num_of_pagedowns -= 1
        time.sleep(2)
 
        html  = driver.page_source
        soup =BeautifulSoup(html,'lxml')
        titles = soup.find_all('span', class_='_2rxlO_K3YY')
        for title in titles:
            rank += 1
            if title.get_text() =='신세계몰':
                print(str(rank)+"번째 : "+title.get_text())
                elem = driver.find_element_by_xpath('//*[@="_2rxlO_K3YY"]/a[contains(@title)]').click()
여기에서 title값으로 selenium click()함수 사용해서 원하는거 클릭할 수 없나요?
 
'신세계몰'이라는 텍스트로 클릭하고 싶은데 방법이 없을까요?

익명 사용자의 이미지

https://kldp.org/node/161530

먼젓번 질문에 답변을 달아 드렸더니 질문 내용을 싹 지우셨더군요.
제가 고쳐 드린 코드는 고스란히 반영되어 있고 말이죠.

정말 별 것 아닌 것 같아 보이는 사소한 행동에서도 상대방의 성의를 가늠해 볼 수 있는 것이지요.

bedals의 이미지

죄송합니다 비슷한 내용으로 글을 계속적으면 실례인것 같아서요
다시 코드 복귀시키도록 하겠습니다. 오해에 소지를 만들어서 정말 죄송합니다.

익명 사용자의 이미지

# -*- coding: utf-8 -*-
"""
Created on Sun May  5 20:44:38 2019
 
@author: Administrator
"""
# -*- coding: utf-8 -*-
"""
Created on Sun May  5 12:55:16 2019
 
@author: Administrator
"""
 
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time
 
 
num_of_pagedowns = 18# 페이지수
rank = 1 
 
 
 
driver = webdriver.Chrome('C:\chromedriver.exe')
 
driver.get('https://m.naver.com')
 
time.sleep(1)
 
# 처음 로드 해서 변수 A 까지
elem = driver.find_element_by_xpath('//*[@id="t21"]/div/button').click() #팝업창 클릭
elem = driver.find_element_by_xpath('//*[@id="MM_SEARCH_FAKE"]') #검색창 클릭
elem.click()
elem = driver.find_element_by_xpath('//*[@id="query"]')
elem.send_keys('박지성')
elem.send_keys(Keys.ENTER)
time.sleep(1)
 
# 두번째 부터 변수 B까지,쇼핑 더보기 내부 로직 시작
elem = driver.find_element_by_xpath('//*[@id="nx_query"]')
elem.clear()
elem.send_keys('남성청결제')
elem.send_keys(Keys.ENTER)
time.sleep(2)
elem = driver.find_element_by_xpath('//*[@id="ct"]/section[1]/div[2]/a').click()
 
for a in range(0,3):
 
    if a == 0:
 
        body = driver.find_element_by_xpath('/html/body')   
 
        while num_of_pagedowns:
            body.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.5)
            num_of_pagedowns -= 1
 
 
        html  = driver.page_source
        soup =BeautifulSoup(html,'lxml')
        titles = soup.find_all('span', class_='_2rxlO_K3YY')
        for title in titles:
            rank += 1
            if title.get_text()=='신세계몰':
                print(str(rank)+"번째 : "+title.get_text())
                time.sleep(2)
    elif 0 < a:
        body = driver.find_element_by_xpath('/html/body')   
        elem = driver.find_element_by_xpath('//*[@id="content"]/div[5]/a[%d]'%(a+1)).click()
        while num_of_pagedowns:
            body.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.5)
            num_of_pagedowns -= 1
        time.sleep(2)
 
        html  = driver.page_source
        soup =BeautifulSoup(html,'lxml')
        titles = soup.find_all('span', class_='_2rxlO_K3YY')
        for title in titles:
            rank += 1
            if title.get_text() =='신세계몰':
                print(str(rank)+"번째 : "+title.get_text())
                elem = driver.find_element_by_xpath('//*[@="_2rxlO_K3YY"]/a[contains(@title)]').click()

여기에서 title값으로 selenium click()함수 사용해서 원하는거 클릭할 수 없나요?

'신세계몰'이라는 텍스트로 클릭하고 싶은데 방법이 없을까요?

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.