[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
用python比较方便
  1. import requests
  2. import time
  3. from bs4 import BeautifulSoup
  4. from urllib.parse import urljoin
  5. from pypinyin import pinyin, lazy_pinyin, Style
  6. def get_lower_pinyin(string):
  7.     pinyin_list = lazy_pinyin(string, style=Style.NORMAL)
  8.     lower_pinyin = ''.join(pinyin_list)
  9.     return lower_pinyin
  10. def get_link_text(url):
  11.     headers = {
  12.         'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
  13.     }
  14.     response = requests.get(url, headers=headers)
  15.     if response.status_code == 200:
  16.         response.encoding = 'UTF8'  # Set the correct encoding
  17.         html = response.text
  18.         soup = BeautifulSoup(html, 'html.parser')
  19.         td_elements = soup.find_all('td')        
  20.         for td in td_elements:
  21.             if td.find('a') and not td.attrs:
  22.                 links = td.find_all('a')
  23.                 for link in links:
  24.                     link_text = link.get_text()
  25.                     if not link_text.isdigit():
  26.                         absolute_url = urljoin(url, link['href'])
  27.                         print(link_text)
  28.                         with open(file_path, 'a') as file:
  29.                             file.write(link_text+","+get_lower_pinyin(link_text)+"\n")
  30.                         time.sleep(0.5)
  31.                         get_link_text(absolute_url)
  32. url = "https://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/"
  33. file_path = r"r:\2.csv"
  34. get_link_text(url)
复制代码

TOP

TOP

已在6楼网盘链接中更新

TOP

返回列表