Python 如何使用beautiful soup/robobrowser选择嵌套链接

Python 如何使用beautiful soup/robobrowser选择嵌套链接,python,django,beautifulsoup,robobrowser,Python,Django,Beautifulsoup,Robobrowser,我正在试验一个新的python库,它基于BeautifulSoup库 我有以下HTML: 我有以下django视图函数 def index(request): p=str(request.POST.get('p', False)) # eg. p='https://www.yahoo.com/' browser = RoboBrowser(history=True) postedmessage = browser.open(p) out = browse

我正在试验一个新的python库,它基于BeautifulSoup库

我有以下HTML:

我有以下django视图函数

def index(request):    

    p=str(request.POST.get('p', False)) # eg. p='https://www.yahoo.com/'
    browser = RoboBrowser(history=True)
    postedmessage = browser.open(p)
    out = browser.select('span.select')

    return HttpResponse(postedmessage)
产量:

<span class="select"><a href="/selector/1">select</a></span>


但是如何使用beautiful soup选择内部标记?

只需将
a
添加到传递给的CSS选择器:

或者,通过将标记名作为属性寻址,导航到第一个匹配的子标记:

out = browser.select('span.select')
links = [span.a for span in out]

只需将
a
添加到传递给的CSS选择器:

或者,通过将标记名作为属性寻址,导航到第一个匹配的子标记:

out = browser.select('span.select')
links = [span.a for span in out]

只需将
a
添加到传递给的CSS选择器:

或者,通过将标记名作为属性寻址,导航到第一个匹配的子标记:

out = browser.select('span.select')
links = [span.a for span in out]

只需将
a
添加到传递给的CSS选择器:

或者,通过将标记名作为属性寻址,导航到第一个匹配的子标记:

out = browser.select('span.select')
links = [span.a for span in out]