【发布时间】:2018-04-03 02:56:01
【问题描述】:
当我运行以下代码时...
import requests
from bs4 import BeautifulSoup
counter = []
url = 'https://www.somemuseum.org/exhibitions/current-exhibitions'
req = requests.get(url)
soup = BeautifulSoup(req.text, 'html.parser')
links = soup.find_all(href="{{ card.url }}")
counter.append(links)
print(counter)
它返回...
<a class="card card--exhibit {{ card.type }}" href="{{ card.url }}">
检查网站上的相同元素显示它存储为...
<a href="/exhibitions/listings/2018/current-listing" class="card card--exhibit is-tier1">
我想做的是类似于以下的for loop...
for link in links:
if card.type=="is-tier1":
exhibit = soup.get('card.url')
counter.append(exhibit)
我是 Beautiful Soup 的新手,因此不胜感激。谢谢。
【问题讨论】:
标签: python-3.x beautifulsoup python-requests