クラスclass1 * OR * クラスclass2のテーブルを見つけることができるように、これを何らかの方法で変更することは可能ですか?
Info = soup.find('table', {'class' :'class1'})
クラスclass1 * OR * クラスclass2のテーブルを見つけることができるように、これを何らかの方法で変更することは可能ですか?
Info = soup.find('table', {'class' :'class1'})
find_all(self, name=None, attrs={}, recursive=True, text=None, limit=None, **kwargs)
Extracts a list of Tag objects that match the given
criteria. You can specify the name of the Tag and any
attributes you want the Tag to have.
The value of a key-value pair in the 'attrs' map can be a
string, a list of strings, a regular expression object, or a
callable that takes a string and returns whether or not the
string matches for some custom definition of 'matches'. The
same is true of the tag name.
例えば:
>>> from bs4 import BeautifulSoup
>>> text = ''.join('<table class="class{}"></table>'.format(i) for i in range(10))
>>> soup = BeautifulSoup(text)
>>>
>>> soup.find_all("table", {"class": ["class1", "class7"]})
[<table class="class1"></table>, <table class="class7"></table>]
>>> import re
>>> soup.find_all("table", {"class": re.compile("class[17]")})
[<table class="class1"></table>, <table class="class7"></table>]
>>>
>>> soup.find_all("table", {"class": lambda x: 3*int(x[-1])**2-24*int(x[-1])+17 == -4})
[<table class="class1"></table>, <table class="class7"></table>]
[わかりました、最後のマッチは多すぎますが、おわかりのように: bool を返すマッチ関数はどれも機能します。]