find_all使用:
item['imgs'] = [i.img.attrs['src'] for i in content.find_all('div', attrs={
'class': 'AdaptiveMedia-photoContainer js-adaptive-photo '})]
soup按照id找节点
p=soup.find("div",{'id':'timeline'})
子节点:直接 "."可取子节点
[i.img.attrs['src'] for i in content.find_all('div', attrs={
'class': 'AdaptiveMedia-photoContainer js-adaptive-photo '})]
children使用
profile = soup.find('div', attrs={'class', 'ProfileHeaderCard'}).children
key_list = []
value_list = []
for son in profile:
if isinstance(son, bs4.element.Tag):
k = son.attrs['class'][0].replace('ProfileHeader', '').replace('Card-', '')
# print k
key_list.append(k)
v = son.get_text().strip()
# print v
value_list.append(v)
item = dict(map(lambda x, y: [x, y], key_list[:-1], value_list[:-1]))
按照class查找不到元素的时候,试试在class名的后面加一个空格,会有意外收获