以下是一个简单的Python爬虫代码示例,用于提取网页中的所有链接:

import requests
from bs4 import BeautifulSoup

# 发送HTTP GET请求获取页面内容
url = 'https://example.com'
response = requests.get(url)

# 使用BeautifulSoup解析页面内容
soup = BeautifulSoup(response.content, 'html.parser')

# 提取页面中的所有链接
links = soup.find_all('a')
for link in links:
    print(link.get('href'))

这个代码使用了requests库发送HTTP GET请求,然后使用BeautifulSoup库解析页面内容。在这个示例中,我们提取了页面中所有的链接并打印出来。你可以根据自己的需求修改代码来进行更复杂的操作。

Python爬虫代码示例:提取网页链接

原文地址: https://www.cveoy.top/t/topic/pE1C 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录