python爬虫示例
时间: 2023-10-05 22:15:01 浏览: 116
python爬虫实例
3星 · 编辑精心推荐
以下是一个Python爬虫示例:
```python
import requests
# 第一个爬虫示例,爬取百度页面
response = requests.get("http://www.baidu.com")
response.encoding = response.apparent_encoding
print("状态码:" + str(response.status_code))
print(response.text)
# 第二个get方法实例
response = requests.get("http://httpbin.org/get")
print(response.status_code)
print(response.text)
# 第三个post方法实例
response = requests.post("http://httpbin.org/post")
print(response.status_code)
print(response.text)
# 第四个put方法实例
response = requests.put("http://httpbin.org/put")
print(response.status_code)
print(response.text)
```
这个示例中,使用了Python的requests库,首先导入该库。然后通过requests.get方法、requests.post方法和requests.put方法,分别发送了GET请求、POST请求和PUT请求。每个请求的URL不同,通过打印response对象的状态码和文本内容,可以获取到相应的返回结果。这些示例可以帮助你理解Python爬虫的基本用法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Python学习 | 10个爬虫实例](https://blog.csdn.net/weixin_39310693/article/details/120401296)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文