티스토리 뷰

WEB

[python] selenium

kiwiiiv 2021. 11. 3. 01:10

 

 

 

from selenium import webdriver
import bs4
dr=webdriver.Chrome('C:\chromedriver.exe')			#exe 파일 위치
dr.implicitly_wait(1)
start_num=228
file=open('C:/Users/User/Desktop/WEB/readfile.txt','r')
buff="000"
for i in range(0,39):
    fw=open('./2장/output'+str(2+i)+'.txt','w',encoding='utf-8')
    url="" 		#url 설정
    
    dr.get(url)
    html=dr.page_source
    soup=bs4.BeautifulSoup(html,'html.parser')
    dr.implicitly_wait(1)
    _input=file.readline()
    if(buff!=_input):
        print(_input)
        buff=_input
        dr.find_element_by_xpath('//*[@id="entry'+str(i+start_num)+'password"]').send_keys(_input)
    
    dr.implicitly_wait(1)
    dr.get(url)
    html=dr.page_source
    soup=bs4.BeautifulSoup(html,'html.parser')
    soup=soup.select_one("body")
    _output=soup.get_text()
    fw.write(_output)


file.close
fw.lose

 

 

find_element_by_xpath

요소의 경로(전체/상대) 정보를 바탕으로 검색

 

dr.find_element_by_xpath('//*[@id="entry'+str(i+start_num)+'password"]').send_keys(_input)

 : id 값이 entry~~password  인 요소 검색

 

 

 

 

 

 

 

그 외


Python Selenium 사용법 [파이썬 셀레늄 사용법, 크롤링] (greeksharifa.github.io)

 

Python, Machine & Deep Learning

Python, Machine Learning & Deep Learning

greeksharifa.github.io

 

'WEB' 카테고리의 다른 글

sql 기본 .. 정리  (0) 2021.07.29
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함