| 123456789101112131415161718192021222324252627282930 |
- import requests
- from bs4 import BeautifulSoup
- # 发送HTTP GET请求
- url = 'https://gs.amac.org.cn/amac-infodisc/res/pof/member/index.html' # 注意:可能需要指定到具体的页面或API端点
- response = requests.get(url)
- # 检查请求是否成功
- if response.status_code == 200:
- print("请求成功")
- # 使用BeautifulSoup解析HTML
- soup = BeautifulSoup(response.content, 'html.parser')
- # 提取表格数据(这里需要根据实际的HTML结构进行调整)
- # 假设表格有一个唯一的ID或类名,例如:<table id="table-id">
- table = soup.find('table', {'id': 'managerList'}) # 替换为实际的ID或类名选择器
- # 提取表格的行和列
- rows = table.find_all('tr')
- data = []
- for row in rows:
- cols = row.find_all('td') # 或者'th',根据需要
- cols = [ele.text.strip() for ele in cols]
- print(f"-------------rows-------------{cols}")
- data.append(cols)
- # 打印提取的数据(或者进行其他处理)
- print(data)
- else:
- print(f"请求失败,状态码:{response.status_code}")
|