我正在尝试与BeautifulSoup合作
for tag in soup.find_all('td',
attrs= {'class': "txtd hidden-phone mobile-f12 stack-mobile"}):
print(tag)
输出为
<td class="txtd hidden-phone mobile-f12 stack-mobile"><a href="/btc/address/16P54KtKHTgkc9d4UQFZf81iv99z41mCsn">16P54KtKHTgkc9d4UQFZf81iv99z41mCsn</a><br/><a href="/btc/address/13ApArvHxx1ATNZ3AtMbvi7AB3MbT1nns9">13ApArvHxx1ATNZ3AtMbvi7AB3MbT1nns9</a><br/></td>
UPD:print(tag.text)
给了我全文但没有空格,我如何分割它?
答案 0 :(得分:0)
16P54KtKHTgkc9d4UQFZf81iv99z41mCsn
13ApArvHxx1ATNZ3AtMbvi7AB3MbT1nns9
您是否尝试遍历tag.text
类似的东西
for text_value in tags.text:
print(text_value)
答案 1 :(得分:0)
您不需要.text
(这是标记中所有字符串的串联)。您需要.strings
:
for tag in soup.find_all('td',
attrs= {'class': "txtd hidden-phone mobile-f12 stack-mobile"}):
print(list(tag.strings))