网页抓取 - 从使用 BeautifulSoup 和 Python 的类中获取文本?

大卫

我想从网站上抓取文本(“显示 650 个结果”)。

我正在寻找的结果是:

 Result : Showing 650 results

以下是 Html 代码:

<div class="jobs-search-results__count-sort pt3">
            <div class="jobs-search-results__count-string results-count-string Sans-15px-black-55% pb0 pl5 pr4">
                Showing 650 results
            </div>

蟒蛇代码:

    response = requests.get(index_url)
    soup = BeautifulSoup(response.text, 'html.parser')
    text = {}
    link = "jobs-search-results__count-string results-count-string Sans-15px-black-55% pb0 pl5 pr4" 
    for div in soup.find_all('div',attrs={"class" : link}):
        text[div.text]
    text

到目前为止,我的代码似乎不起作用。

cs95
  1. soup.find_all如果您只寻找一个元素,则不需要soup.find同样适用

  2. 您可以使用tag.string/ tag.contents/tag.text访问内部文本


div = soup.find('div', {"class" : link})
text = div.string

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

无法使用python和beautifulsoup抓取网页中的某些href

使用BeautifulSoup Python抓取网页

使用 Python 3.7 中的 Beautifulsoup 从 WSJ 抓取网页文章?

使用嵌套 for 循环抓取网页,python3 中的 BeautifulSoup

使用 BeautifulSoup 和 json 进行网页抓取

使用 Python BeautifulSoup 进行网页抓取

使用 Beautifulsoup 的 Python 网页抓取:lowes 商店

使用 BeautifulSoup 进行网页抓取 -- Python

使用 BeautifulSoup 和 Selenium 的网页抓取网站不会检测网页中的表格元素

使用 BeautifulSoup 获取空列表的网页抓取

使用BeautifulSoup从网页中抓取特定链接

网页抓取 Python BeautifulSoup

使用BeautifulSoup抓取网页

使用 BeautifulSoup 抓取网页

使用 Python 和 BeautifulSoup 的网页抓取 - 错误消息不确定如何修复

如何使用python和Beautifulsoup抓取网页的第二个<p>

使用python,BeautifulSoup和pandas'read_html'进行网页抓取的问题

用python和beautifulSoup抓取网页的奇怪结果

使用 Selenium 和 BeautifulSoup 进行 Zillow 网页抓取

使用 Selenium 和 BeautifulSoup 进行网页抓取返回空列表

使用Python登录网站和网页抓取

Python 网页抓取未使用 BeautifulSoup 显示所有行

在 python 网页抓取中使用 Selenium 对 BeautifulSoup 进行分页

python - 使用 BeautifulSoup 抓取网页的更有效方法

(初级) Python网页抓取 BeautifulSoup

网页抓取 Python (BeautifulSoup,Requests)

python beautifulsoup 网页抓取问题

使用 Beautifulsoup 抓取 UEFA 网页

如何使用 Python 和 BeautifulSoup 从 html 表中抓取数据?