以下是一个简单的Python代码,用于从百度文库中采集数据:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://wenku.baidu.com/view/xxx.html' # 替换为需要采集的文档链接
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 获取文档标题
title = soup.find('title').text.strip()
# 获取文档内容
content = ''
for page in soup.select('.reader-page'):
content += page.text.strip() + '\n'
print(title)
print(content)
```
请注意,此代码仅适用于公开的百度文库文档。如果您需要采集私人文档或需要登录才能访问的文档,则需要进行额外的处理。