본문으로 바로가기

BeautifulSoup 웹파싱

category Coding/Python 2016. 1. 29. 18:20
반응형


[ex src]

<a href="index.php">Home</a>

<a href="#">Sign up<br></a>

<a href="#">Login</a>


<input type="text" class="form-control" id="inputID" placeholder="ID" name="userid">

<input type="password" class="form-control" id="inputPW" placeholder="Password" name="userpw">


soup('input') : 모든 input 태그 반환

-> [<input class="form-control" id="inputID" name="userid" placeholder="ID" type="text">\n</input>, <input class="form-control" id="inputPW" name="userpw" placeholder="Password" type="password">]


soup('input')[0].string : 첫번째 input 태그의 string 반환

-> 


soup.input['id'] : 첫번째 input태그의 id값 반환

-> inputID


soup.find_all('a') - 모든 a 태그 반환

-> [<a href="index.php">Home</a>, <a href="#">Sign up<br/></a>, <a href="#">Login</a>]


soup.find_all('a')[0].string - 첫번째 a태그의 string 반환

-> Home


soup.find_all('a')[0]['href'] - 첫번째 a태그의 href값 반환

-> index.php



내용추가중..

반응형

'Coding > Python' 카테고리의 다른 글

파이썬 정규식 정리  (0) 2016.02.25
Python Proxy check  (0) 2016.01.30
Pytesser OCR  (0) 2016.01.27
소켓 통신할때 Response 못받아오는 문제  (0) 2016.01.08
Selenium 경로설정  (0) 2016.01.08