2017-12-10 28 views
-1
from urllib.request import urlopen 
from bs4 import BeautifulSoup 
html = urlopen("http://companyinfo.stock.naver.com/v1/company/c1010001.aspx?cmp_cd=056190") 
bsj = BeautifulSoup(html, 'html.parser') 
table = bsj.find_all("table" , {"class" : "gHead01 all-width"}). 

표의 캡션 속성은 시각 장애인입니다.soup.find ("table", { "caption": "blind"})

The table.png

은 내가 표를 얻기 위해 무엇을해야합니까? ..

답변

0

정확 하. <caption> 요소는 테이블의 첫 번째 하위 요소입니다.

BeautifulSoup.find에 함수를 전달하여 지정된 조건과 일치하는 태그를 반환 할 수 있습니다.

soup = BeautifulSoup(markup, "html5lib") 

def table_having_caption_text(text): 
    def query(tag): 
     first_child = tag.next 
     return (
      tag.name=="table" 
      and first_child.name == 'caption' 
      and first_child.text == text 
     ) 
    return query 

print(
    soup.find(
     table_having_caption_text("Blind") 
    ) 
)