小编Bre*_*ott的帖子

Python和BeautifulSoup开幕页面

我想知道如何使用BeautifulSoup打开列表中的另一个页面?我已按照本教程进行操作,但是并没有告诉我们如何打开列表中的另一页。另外,我如何打开嵌套在类内部的“ a href”?

这是我的代码:

# coding: utf-8

import requests
from bs4 import BeautifulSoup

r = requests.get("")
soup = BeautifulSoup(r.content)
soup.find_all("a")

for link in soup.find_all("a"):
    print link.get("href")

    for link in soup.find_all("a"):
        print link.text

    for link in soup.find_all("a"):
        print link.text, link.get("href")

    g_data = soup.find_all("div", {"class":"listing__left-column"})

    for item in g_data:
        print item.contents

    for item in g_data:
        print item.contents[0].text
        print link.get('href')

    for item in g_data:
        print item.contents[0]
Run Code Online (Sandbox Code Playgroud)

我正在尝试从每个公司的标题中收集href,然后将其打开并抓取该数据。

python beautifulsoup web-scraping

5
推荐指数
1
解决办法
8897
查看次数

标签 统计

beautifulsoup ×1

python ×1

web-scraping ×1