我想知道如何使用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,然后将其打开并抓取该数据。