1 回答
TA贡献2019条经验 获得超9个赞
替换为:
area.find('a').attrs['href']
完整代码
import requests
from bs4 import BeautifulSoup
def scrape():
url = 'https://disboard.org/search?keyword=hacking'
response = requests.get(url).content
soup = BeautifulSoup(response, 'html.parser')
areas = soup.find_all('div', class_='server-name')
for area in areas:
print(area.find('a').attrs['href'])
if __name__ == '__main__':
scrape()
输出
/server/484696439063314482
/server/560847285874065408
/server/715563459739385886
/server/720783958966796309
/server/471545766134153237
/server/733350720690061383
/server/653642434948890626
/server/589905664277610521
/server/729633522565775381
/server/734257173890334832
/server/637702746954530865
/server/326839256758616068
/server/495986950478757891
添加回答
举报