Python 使用beautifulsoup时遇到的困难
我正在努力搜刮一些网站,但是我在收集我想要的东西时遇到了一些困难:Python 使用beautifulsoup时遇到的困难,python,web-scraping,beautifulsoup,Python,Web Scraping,Beautifulsoup,我正在努力搜刮一些网站,但是我在收集我想要的东西时遇到了一些困难: import requests from bs4 import BeautifulSoup import time from datetime import date, datetime, timedelta url = 'https://cerbios.swiss/news-events/news/' page = requests.get(url) soup = BeautifulSoup(page.cont
import requests
from bs4 import BeautifulSoup
import time
from datetime import date, datetime, timedelta
url = 'https://cerbios.swiss/news-events/news/'
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
results_date = soup.find(class_='entry-title')
print(results_date)
这是我的代码,这段代码的输出是:
<h3 class="entry-title">
<a href="https://cerbios.swiss/new-400-mhz-nmr-in-cerbios/" rel="bookmark" title="NEW 400 MHZ NMR IN
CERBIOS">NEW 400 MHZ NMR IN CERBIOS</a>
</h3>
这很好,但我真正想要的是“href”,以便在输出中只包含URL,我真的不知道如何做到这一点,我尝试了以下行:results\u URL=soup.find(class='entry-tite')['href']
但它不起作用,因为类“entry title”没有“href”的内容。
如果有人能帮助我,我将非常高兴。您试图访问
元素上不存在的href
属性。您可以继续使用find()
访问
元素,也可以使用更具体的选择器
soup.find(class_='entry-title').find('a')['href']
或
您正在尝试访问
元素上不存在的href
属性。您可以继续使用find()
访问
元素,也可以使用更具体的选择器
soup.find(class_='entry-title').find('a')['href']
或