response.content 와 response.text 의 차이

          .content : in bytes

          .text : in unicode

 

response

text

 

webdriver로 page source 가져오기

soup = BeautifulSoup(page_driver.page_source, 'lxml')

page_source

 

 

list의 내용을 다 지울때 clear() 함수 사용

list clear()

 

 

Beautifulsoup에서 tag가 특정 attribute를 갖고 있는지 확인하는 함수

tag_name.has_attr(‘attribute_name’)

없는지 확인하려면 not tag_name.has_attr(‘attribute_name’) 처럼 not을 붙여 사용

has_attr

 

 

Beautifulsoap object를 이용해 문서에서 attribute의 값을 가져올때,

<p>
    Back to the 
    <a rel="index">
           homepage
    </a>
</p>

위 문서에서 soup.a[‘rel’] 형태로 값 ‘index’을 가져온다.

get_attribute_text

 

webdriver를 context manager로 사용하면 실행이 끝나고 브라우저도 닽혀진다.

context_manager

댓글 남기기