如何在span标签内打印文字? 这是我的代码。有点天真
https://i.stack.imgur.com/c4JIe.png
from bs4 import BeautifulSoup
import requests
def fun(max_pages):
page = 1
while page<=max_pages:
url = 'https://soundcloud.com/suyash-chavan-4'
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text , 'html.parser')
link = soup.find_all('div', {'class':'soundTitle__titleContainer'})
for x in link:
inner = x.find_all('div', {'class':'soundTitle__usernameTitleContainer'})
for a in inner:
before_span = a.find_all('a',{'class':'soundTitle__title sc-link-dark'})
for span in before_span:
href = span.get('span')
print(href.string)
fun(1)
答案 0 :(得分:0)
而不是使用href.string
使用href.text