【发布时间】:2021-03-18 07:55:25
【问题描述】:
我在抓取 <div> 已经在 <div> 中的名称时遇到了一些麻烦(即使我尝试搜索特定的卡体,它也可以与完整的其他部分一起使用)
https://namemc.com/minecraft-names?sort=asc&length_op=&length=3&lang=&searches=500
我需要这部分:
<div class="card-body p-0">
<div class="row no-gutters py-1 px-3">
<div class="col col-lg order-lg-1 text-nowrap text-ellipsis">
<a href="/name/example" translate="no">example</a>
即使我找到了名字,但它们不在我想要的列表中。有人知道如何找到它们吗? 我正在使用 beautifulsoup 和 lxml。我的部分代码:
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://namemc.com/minecraft-names?sort=asc&length_op=&length=3&lang=&searches=500').text
soup = BeautifulSoup(html_text, 'lxml')
itemlocator = soup.find('div', class_='card-body p-0')
for items in itemlocator:
print(items)
【问题讨论】:
标签: python html python-3.x web-scraping beautifulsoup