写一个爬取http://www.dce.com.cn/dalianshangpin/xqsj/tjsj26/jdtj/rcjccpm/index.html网页持仓数据的Python代码
时间: 2023-12-06 08:04:18 浏览: 195
抓取网页数据的代码
4星 · 用户满意度95%
以下是爬取http://www.dce.com.cn/dalianshangpin/xqsj/tjsj26/jdtj/rcjccpm/index.html网页持仓数据的Python代码:
```python
import requests
from bs4 import BeautifulSoup
url = 'http://www.dce.com.cn/dalianshangpin/xqsj/tjsj26/jdtj/rcjccpm/index.html'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
table = soup.find('table', {'class': 'table'})
rows = table.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [col.text.strip() for col in cols]
print(cols)
```
阅读全文