How to capture web content and save it using Python?
In Python, you can use the requests library to retrieve web content and use file operations to save the retrieved content. Below is an example code:
import requests
# 抓取网页内容
url = 'http://www.example.com'
response = requests.get(url)
content = response.text
# 保存抓取到的内容
with open('output.html', 'w', encoding='utf-8') as f:
f.write(content)
In the code above, start by using the requests library to send a GET request to fetch the webpage content, then save the retrieved content to a file named output.html. You can modify the URL and file name as needed to fetch different webpage content and save it to different files.