Python:BeautifulSoup find_all search in<;a>;标签还是其他东西?

Python:BeautifulSoup find_all search in<;a>;标签还是其他东西?,python,html,web-scraping,Python,Html,Web Scraping,有人能确认“全部查找”是否自动在标签中搜索吗?我期待着“找到所有”能找到所有有“a”的东西。但事实上,它能捕捉到里面的一切”, , , , , , , , , 查找所有() find_all()方法查看标记的子体,检索与筛选器匹配的所有子体,并返回包含结果的列表 find()与find\u all() 如果只想获得与筛选器匹配的第一个匹配项,请使用find() 如果要获取与筛选器匹配的所有匹配项,请使用find_all() 示例-获取所有href from bs4 import Beauti

有人能确认“全部查找”是否自动在标签中搜索吗?我期待着“找到所有”能找到所有有“a”的东西。但事实上,它能捕捉到里面的一切”, , , , , , , , , 查找所有()

find_all()
方法查看标记的子体,检索与筛选器匹配的所有子体,并返回包含结果的列表

find()与find\u all()

  • 如果只想获得与筛选器匹配的第一个匹配项,请使用
    find()
  • 如果要获取与筛选器匹配的所有匹配项,请使用
    find_all()
示例-获取所有href

from bs4 import BeautifulSoup
import requests
url = "https://boston.craigslist.org/search/sof"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
[a['href'] for a in soup.find_all('a',href=True)]
输出 (您可能需要迭代并清理它,或者自定义上面的过滤器,以仅获取包含
http
,…)的
href


我不明白你的意思,你在搜索“a”,BeautifulSoup会给你“a”“问题是,有错误吗?如果你在一个文本中有一个错误怎么办?”?例如,一只狐狸快速跳到一棵树上,这也会被捡起来吗?好的,谢谢你的反馈!很高兴提供帮助,欢迎使用Stack Overflow。如果此答案或任何其他答案解决了您的问题,请将其标记为已接受-
[<a class="appstorebtn" href="https://play.google.com/store/apps/details?id=org.craigslist.CraigslistMobile">
         Android
     </a>,
 <a class="appstorebtn" href="https://apps.apple.com/us/app/craigslist/id1336642410">
         iOS
     </a>,
 <a class="header-logo" href="/" name="logoLink">CL</a>,
 <a href="/">boston</a>,
 <a href="https://post.craigslist.org/c/bos">post</a>,
 <a href="https://accounts.craigslist.org/login/home">account</a>,
 <a class="favlink" href="#"><span aria-hidden="true" class="icon icon-star fav"></span><span class="fav-number">0</span><span class="fav-label"> favorites</span></a>,
 <a class="to-banish-page-link" href="#">
 <span aria-hidden="true" class="icon icon-trash red"></span>
 <span class="banished_count">0</span>
 <span class="discards-label"> hidden</span>
 </a>,
 <a class="header-logo" href="/">CL</a>,
from bs4 import BeautifulSoup
import requests
url = "https://boston.craigslist.org/search/sof"
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data,'html.parser')
[a['href'] for a in soup.find_all('a',href=True)]
['https://play.google.com/store/apps/details?id=org.craigslist.CraigslistMobile',
 'https://apps.apple.com/us/app/craigslist/id1336642410',
 '/',
 '/',
 'https://post.craigslist.org/c/bos',
 'https://accounts.craigslist.org/login/home',
 '#',
 '#',
 '/',
 'https://accounts.craigslist.org/savesearch/save?URL=https%3A%2F%2Fboston%2Ecraigslist%2Eorg%2Fd%2Fsoftware%2Dqa%2Ddba%2Detc%2Fsearch%2Fsof',
 '/d/software-qa-dba-etc/search/sof',
 '/d/software-qa-dba-etc/search/sof',
 '/d/software-qa-dba-etc/search/sof?sort=date&',
...]