[Python] find_all function 2020.2.7

.find_all(name,attrs,recursive,string,**kwargs)

name: the name of the search character string tag
attrs: search character string tag attribute value, can be marked attribute search
recursive: whether all the descendants retrieval, default True
String <> .... </> string region retrieving string


soup.find_all ( 'a')
to find a tag

soup.find_all ( 'a', 'b ')
a list of copying find a tag as tag and b

Tag in soup.find_all for (True)
Print (tag.name)
to print out all the labels

import re # regular expression library
for Tag in soup.find_all (re.compile ( 'b')):
Print (tag.name)
begin with b label

soup.find_all ( 'p', 'course ')
to print labels p course class attribute tags

soup.find_all (id = 'link1')
printed label id = attribute of link1

soup.find_all (id = re.compile ( 'link ')
to print labels, such as the presence of link link, link1, link2 ...... like the id

soup.find_all ( 'a')
soup.find_all ( 'a', recursive This = False)
from the root node soup without a son node tag

soup.find_all (string = "Basic Python" )
can be retrieved Basic Python
if the introduction of regular expression library
soup.find_all (string = re.compile ( "python "))
can retrieve all the contents of the internal label containing the python

Guess you like

Origin www.cnblogs.com/zlc364624/p/12274685.html