member.py 1.1 KB

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