Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用beautifulsoup时遇到的困难_Python_Web Scraping_Beautifulsoup - Fatal编程技术网

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']