使用requests库爬取https://www.xynu.edu.cn/
时间: 2023-08-10 12:02:28 浏览: 121
好的,我可以为您提供一些简单的代码来使用requests库爬取https://www.xynu.edu.cn/的内容:
```python
import requests
url = "https://www.xynu.edu.cn/"
response = requests.get(url)
print(response.text)
```
这段代码会向指定的url发出一个GET请求,并返回响应内容。我们可以通过`response.text`来获取响应内容。当然,您可以根据实际需求对代码进行修改和优化。
相关问题
用requests爬取https://weibo.com/的信息
好的,您可以使用以下代码进行爬取:
```python
import requests
url = 'https://weibo.com/'
response = requests.get(url)
print(response.text)
```
请注意,这是一个简单的示例,实际爬取需要处理反爬机制和登录等问题,同时也需要遵守网站的使用规定。
用requests爬取http://www.8800txt.com/txt/435021/23046123.htm
好的,以下是使用Python中的requests库爬取http://www.8800txt.com/txt/435021/23046123.htm的示例代码:
```python
import requests
url = 'http://www.8800txt.com/txt/435021/23046123.htm'
response = requests.get(url)
if response.status_code == 200:
print(response.text)
else:
print('请求失败!')
```
解释一下代码:
- 第1行:导入requests库;
- 第3行:设置要爬取的URL地址;
- 第4行:使用requests库的get()方法发送GET请求,并将响应结果保存在response对象中;
- 第6-9行:判断响应状态码是否为200(即请求成功),如果是,则打印响应内容;否则,提示请求失败。
你可以将以上代码保存为一个.py文件,然后运行它,即可看到该网页的HTML内容。
阅读全文
相关推荐















