用美丽的汤刮网寻找动物

时间:2019-10-24 08:18:19

标签: python web-scraping beautifulsoup

我正在尝试从搜索引擎网站上抓狗 在我的例子中是博美犬 我不确定soup.find_all

应该有什么

这就是我所做的:

url = "https://www.winwin.co.il/Animals/Search/SearchResults/AnimalPage.aspx?search=f1b130870fcd32672a71e39ae8e26898"


response = requests.get(url)


data = response.text


soup = BeautifulSoup(data,'html.parser')

dog=soup.find_all("div",{"class":"ContainerSEOTxt"})

1 个答案:

答案 0 :(得分:2)

find_all的结果必须是项的数组

soup.find_all("a")

 print output

 [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-all

divs = soup.find_all('div', 'class_name')

如果您有多个类名,只需将类名列表作为参数传递

divs = soup.find_all('div', ['class1', 'class2'])