Retrieve the NT user name(转)

Retrieve the NT user name on an intranet. Strips the domain name from the returned string.


 
  Retrieve the NT user name on an intranet. Strips the domain name from the returned string.

  '**************************************
  ' Name: NT User Name
  ' Description:Retrieve the NT user name
  '  on an intranet. Strips the domain name f
  '  rom the returned string.
  ' By: Joe McDonnell
  '
  'This code is copyrighted and has  ' limited warranties.Please see http://w
  '  ww.Planet-Source-Code.com/xq/ASP/txtCode
  '  Id.6689/lngWId.4/qx/vb/scripts/ShowCode.
  '  htm  'for details.  '**************************************
  
  You can easily Get the NT logon name For a user by using:
  user=request.servervariables("logon_user") OR
  user=request.servervariables("remote_user")
  This will return a String like "mydomain/myname"
  You can Get just the user name by using INSTRREV. Where INSTR returns the position of the first search character INSTR will return the last. Your code will be something like:
    MyVar=request.servervariables("logon_user")
  MyPos = InstrRev(MyVar, "/", -1, 1)
  UserName=Mid(MyVar,MyPos+1,Len(MyVar))
  %>
  You can also use this To return file names from paths etc.


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10294527/viewspace-124726/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10294527/viewspace-124726/

### 如何进行企业绿色型相关的数据爬取 对于企业绿色型相关数据的爬取,可以从公开的企业报告、政府发布的政策文件、新闻报道以及行业研究报告等多个渠道入手。考虑到目标数据可能分布在不同的网页结构中,采用合适的工具和技术至关重要。 #### 工具选择 为了高效地完成这项工作,推荐使用 Python 编程语言及其生态系统内的多个库来辅助数据抓取过程: - **requests**: 用于发起 HTTP 请求并接收响应; - **BeautifulSoup 或 lxml**: 解析 HTML 文档,提取所需信息; - **pandas 和 numpy**: 处理和清洗所获得的数据集; - **matplotlib 及其他可视化库**: 对初步处理后的数据做简单图形化表示以便于理解[^4]。 #### 技巧分享 当面对具有复杂动态加载机制的目标站点时,可以考虑引入 Selenium 这样的浏览器自动化框架模拟真实用户的浏览行为,从而绕过某些类型的反爬虫措施。另外,在编写爬虫程序之前应当仔细阅读目标网站的服务条款,确保活动合法合规。同时注意设置合理的请求间隔时间以免给服务器造成过大压力[^3]。 ```python import requests from bs4 import BeautifulSoup import time import random def fetch_page(url): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', } try: response = requests.get(url, headers=headers) if response.status_code == 200: return response.text else: print(f"Failed to retrieve page {url}") return None except Exception as e: print(e) return None def parse_html(html_content): soup = BeautifulSoup(html_content, 'html.parser') # 根据具体页面结构调整下面的选择器表达式 items = [] for item in soup.select('.item-class'): title = item.find('h2').get_text(strip=True) link = item.find('a')['href'] summary = item.find('p', class_='summary').get_text(strip=True) items.append({ 'title': title, 'link': link, 'summary': summary }) return items if __name__ == '__main__': base_url = "http://example.com/green-transition" pages_to_scrape = range(1, 6) # 假设有五页内容 all_items = [] for i in pages_to_scrape: url = f"{base_url}/page/{i}" html = fetch_page(url) if not html: continue parsed_data = parse_html(html) all_items.extend(parsed_data) sleep_time = random.uniform(1, 3) time.sleep(sleep_time) print(all_items[:5]) # 输出前五个样本查看效果 ``` 此段代码展示了基本的网页抓取逻辑,包括发送HTTP GET请求获取HTML源码、解析DOM树定位感兴趣的内容节点,并适当加入随机延时以降低被封禁的风险。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值