python爬虫爬取网页数据
时间: 2023-07-09 19:52:44 浏览: 59
Python是一个非常流行的编程语言,也是许多爬虫工具的首选。在Python中,可以使用requests模块来发送HTTP请求,使用Beautiful Soup模块来解析HTML文档。以下是一个简单的Python爬虫示例:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.example.com'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 打印网页标题
print(soup.title.string)
# 找到所有的链接
for link in soup.find_all('a'):
print(link.get('href'))
```
这个示例演示了如何使用Python爬虫请求一个网页,解析HTML文档,并打印出网页标题和所有链接。当然,这只是一个简单的示例,实际的爬虫程序可能需要更复杂的逻辑来处理不同的网站和数据。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)