콘텐츠 관리 시스템으로 모든 것을 마이그레이션하려는 장기적인 목표로 친구의 (구조적이거나, 거추장스러운) 웹 사이트를 긁어 모으는 과정을 밟아서 BeautifulSoup 및 Python 베어링을 얻고 있습니다.스크래핑 테이블
내가 가진 콘솔에서 정확히 하나의 셀 (soup = BeautifulSoup(urllib2.urlopen("http://www.bicyclepaintings.com/archive/index.html")
) 당겨 경우 나 문자열을 잡아 당겨 함께 놀러 수
cell = soup.find_all('td',{'valign':'bottom'})[3]
합니다. 이 모든 것은 잘 작동합니다 : cell.br.next_sibling
, cell.find('b').text
. 내가 루프에 대한 모든 세포를 통해 루프를 시도 할 때 :
def parse_archive(url):
soup = get_soup(url)
paintings = []
for cell in soup.find_all('td',{'valign':'bottom'}):
painting_title = cell.find('b').text
painting_media = cell.br.next_sibling
record = painting_title, painting_media
paintings.append(record)
return paintings
를 내가 속성 오류 (AttributeError: 'NoneType' object has no attribute 'text'
)을 얻는다. 나는 통해 다시 반복하여 동일한 정보의 일부를 얻을 수 있습니다 :
for item in cell.find_all('b'):
painting_title = item.text
하지만 <br/>
에 형제에서 얻을 수있는 방법이 표시되지 않으며 작동 왜 (이 점 이상) 이해가 안 돼요 하나의 항목을 꺼내지 만 for 루프를 통해 액세스하려고하면 그렇지 않습니다. 내가 여기서 무엇을 놓치고 있니?
작동. 'var = one.thing else else '구문이 "title is None : continue"대신 작동합니까? – Amanda
제목이 아름다운 수프 태그 여야하므로 작동하지 않습니다. –
cell.find_all ('font')의 그래프에서'if len (graph.contents)> 4 :'inside '를 사용하여 빈 줄을 배제했습니다. – Amanda