利用WebBrowser读取网页中表格的数据

合集下载

webscraper提取二维表格抓取技巧

webscraper提取二维表格抓取技巧

webscraper提取二维表格抓取技巧要提取二维表格数据,可以使用Python中的一些库来进行网页抓取和数据提取。

以下是一些常用的技巧和库:1. 使用requests库发送HTTP请求获取网页内容。

2. 使用BeautifulSoup库解析HTML文档,找到表格的标签和属性。

3. 使用Pandas库将表格数据转换为DataFrame对象,方便进行数据处理和分析。

4. 根据表格的结构和特点,使用CSS选择器或XPath来定位和提取所需的表格数据。

5. 使用正则表达式对提取到的数据进行进一步的处理和清洗。

6. 遍历表格的行和列,将提取到的数据保存到一个数据结构中,例如列表或字典。

以下是一个示例代码,演示如何使用上述技巧提取网页中的二维表格数据:```pythonimport requestsfrom bs4 import BeautifulSoupimport pandas as pd# 发送HTTP请求获取网页内容url = ""response = requests.get(url)html_content = response.text# 使用BeautifulSoup解析HTML文档soup = BeautifulSoup(html_content, "html.parser")# 找到表格的标签table = soup.find("table")# 使用Pandas将表格数据转换为DataFrame对象df = pd.read_html(str(table))[0]# 对提取到的数据进行进一步处理和清洗# ...# 打印提取到的表格数据print(df)```需要根据具体的网页结构和表格特点进行相应的调整和处理。

以上是一种常用的方法,希望对你有帮助。

如何提取含有iframe网页(HTML)的表格(table)数据

如何提取含有iframe网页(HTML)的表格(table)数据

如何提取含有iframe网页(HTML)的表格(table)数据如何提取含有iframe网页(HTML)的表格(table)数据2008-09-23 17:24:54| 分类: Delphi |举报 |字号订阅如何提取含有iframe网页(HTML)的表格(table)数据想提取网页里的表格(table标签)数据,因为session的原来,所以用了,但些网页被包含在一个iframe里,所以在论坛上找到了一高人的代码(参考代码一),用FrameWin.document.body.outerHTML得到了源码,但问题是,我想得到table表里的数据,好像没有FrameWin.document.all.tags('table').item(0).outerHTML这种形式,但WebBrowser却有.如参考代码二,因为要提取的网页的表格是通过另一同级iframe网页的javascript赋值的,所以不能直接通过FrameWin.document.body.outerHTML用字符串直接分析,那样得的数据都是空格。

大家有什么好办法。

参考代码一:usr mshtml;procedure TMainForm.ToolButton56Click(Sender: TObject );varIndex: Integer;Document: IHTMLDocument2;FrameIdx: OleVariant;FrameDis: IDispatch;FrameWin: IHTMLWindow2;beginwhile Webbrowser1.ReadyState <> READYSTATE_COMP LETE doApplication.ProcessMessages;if WebBrowser1.Document = nil then Exit;if WebBrowser1.Document.QueryInterface(IHTMLDocume nt2, Document) <> 0 then Exit;if Document.frames.length > 0 thenbeginfor Index := 0 to Document.frames.length - 1 do beginFrameIdx := Index;FrameDis := Document.frames.item(FrameIdx);if FrameDis.QueryInterface(IHTMLWindow2, FrameWin) <> 0 then Exit;ShowMessage(FrameWin.document.body.outerHTML);//FrameWin.document 就是你要的每个 Frame 的文档end;end;end;参考代码二:procedure Form1.Button1Click(Sender: TObject);var i,j : integer;GetTable : OleVariant;beginWebBrowser1.Navigate('/minalnew/MyHTML.htm');while WebBrowser1.ReadyState < READYSTATE_INTERA CTIVE do //頁面激活Application.ProcessMessages;Memo1.Lines.Add(WebBrowser1.OleObject.Document.all.ta gs('table').item(0).outerhtml);GetTable:= WebBrowser1.OleObject.Document.all.tags('tab le').item(0);For i:=0 to (GetTable.Rows.Length-1) dobeginFor j:=0 to (GetTable.Rows.Item(i).Cells.Length-1) do beginMemo2.Lines.Add(GetTable.Rows.Item(i).Cells.Item(j).innerh tml);end;end;end;解决了.不过是另开的一个贴子的办法解决的.爽.方法见:/Expert/topic/3537/3537880.xml?t emp=.4540979Topto:fayeflash(我爱阿菲)第一,用参考代码一的方法得到iframe的HTML源代码,类型为IHTMLDocument,第二,使用IHTMLTABLE,IHTMLRows,就可以正确得到网页表格数据了.就算表格数据是由javascript等脚本赋值也可以正确提出数据。

web scraper用法(二)

web scraper用法(二)

web scraper用法(二)Web Scraper用法Web Scraper是一种用于从网页中提取数据的工具。

它可以自动化网页上的信息提取过程,轻松获取所需数据。

以下是一些Web Scraper的常见用法:1. 数据收集•数据采集:Web Scraper可以用于从网站上收集数据。

例如,一个电商网站可能有成千上万的产品列表,你可以使用WebScraper自动抓取每个产品的名称、价格和描述等信息。

•数据清洗:获取到的网页数据通常需要进行清洗和整理,以方便进一步分析。

Web Scraper可以自动化这个过程,帮助你提取和清洗原始数据。

2. 竞争情报•价格比较:Web Scraper可以用于收集竞争对手的产品价格数据,帮助你实时了解市场价格变动情况,并根据情报做出相应调整。

•产品评价:通过抓取竞争对手的产品评价数据,你可以了解用户对他们产品的反馈和意见。

这可以帮助你改善自己的产品和服务。

3. 媒体监测•新闻爬取:Web Scraper可以自动抓取新闻网站的头条新闻,并将其保存到数据库中,以供进一步分析和报告。

•社交媒体分析:通过抓取社交媒体平台上的数据(如Twitter、Facebook等),你可以了解用户对你的品牌或产品的看法和反馈。

这对于改善品牌形象和营销策略非常有价值。

4. SEO优化•关键词研究:Web Scraper可以帮助你抓取搜索引擎结果页数据,以了解特定关键词的搜索结果和排名情况。

这可以帮助你优化网站的SEO策略。

•竞争对手分析:通过抓取竞争对手的网页数据,你可以了解他们的关键词使用情况、页面结构和内部链接策略等。

这可以帮助你改进自己的网站并提高排名。

5. 价格监测•促销监测:通过抓取网站上的促销信息,你可以及时了解市场上类似产品的价格变动情况。

这可以帮助你制定促销策略并定价产品。

•库存监测:使用Web Scraper抓取网站上的库存信息,你可以实时了解产品的库存状况,并根据需要及时补货。

前端开发知识:如何实现Web爬虫和数据抓取

前端开发知识:如何实现Web爬虫和数据抓取

前端开发知识:如何实现Web爬虫和数据抓取Web爬虫和数据抓取是前端开发中重要的一部分,它能够帮助我们获取到需要的数据,方便我们进行网站数据分析和业务开发。

下面将详细讲解如何实现Web爬虫和数据抓取。

一、什么是Web爬虫和数据抓取Web爬虫指的是网络爬虫(英语:web crawler),也称网络蜘蛛(spider),是一种用于自动抓取网页的程序。

Web爬虫能够自动访问网页,并且不断地进行抓取、解析和存储数据,最终形成数据储存的结果。

数据抓取是指在Web上寻找有用数据的行为。

数据抓取可以应用于数据收集、数据分析、各种类型的自动化和数据挖掘等方面。

数据抓取可以自动的去抓取互联网上的数据,节省大量的时间和人力成本。

二、Web爬虫和数据抓取的实现方式Web爬虫和数据抓取的实现方式可以分为以下几种:1.使用现成的爬虫框架现今市场上有许多优秀的爬虫框架可以用来实现Web爬虫和数据抓取,如Python的Scrapy框架、Node.js的Cheerio框架等。

这些框架已经集成了大量的功能和模块,可以帮助开发者快速构建一个稳定的爬虫。

2.使用第三方API有些网站可能没有反爬虫的措施,可以直接通过第三方API获取数据。

比如可以使用Facebook Graph API获取Facebook上的相关数据,使用Twitter API获取Twitter上的相关数据等。

3.直接使用HTTP请求开发者也可以直接使用HTTP请求获取网页数据。

这种方式相对来说比较原始,但是可以充分展现开发者的技术能力,获得更灵活的控制权。

三、Web爬虫和数据抓取的核心技术Web爬虫和数据抓取的核心技术包括以下几个方面:1.数据解析数据解析是Web爬虫和数据抓取中的重要部分,也是最为复杂的部分。

数据解析的目的是把获取到的数据转化为需要的格式,比如JSON、XML、CSV等。

开发者需要了解网页的HTML结构和DOM节点,才能够很好的进行数据解析。

2.数据清洗由于网站上的数据通常是非常复杂的并且包含许多无用信息,因此需要对数据进行清洗和处理,以筛选出所需的信息。

webscraper 使用方法

webscraper 使用方法

webscraper 使用方法网页爬取器的使用方法网页爬取器(webscraper)是一种用于从互联网上收集数据的工具。

它可以自动访问网页,并从网页的HTML代码中提取所需要的数据。

这种工具在信息收集、市场调研和数据分析等领域非常有用。

首先,为了使用网页爬取器,您需要选择一个合适的编程语言和库来编写爬取代码。

常用的语言包括Python、JavaScript和Ruby。

其中,Python语言的Beautiful Soup和Scrapy库是非常受欢迎的选择,它们提供了简洁而强大的功能。

在编写爬取代码之前,您需要明确您希望从哪些网页上收集数据。

这可以包括特定的网站、特定的页面或者整个网站。

了解所要爬取的网页的结构和格式是非常重要的,因为您需要根据这些信息来定制您的爬取代码。

接下来,您需要设置爬取器的参数。

这包括指定爬取的起始页面、设置爬取的深度(即爬取多少层的链接)、设定每个页面的爬取间隔时间等。

合理地设置这些参数可以有效控制爬取的效率和效果。

编写爬取代码时,您需要指定如何定位和提取所需的数据。

通常,您可以使用HTML标签、CSS选择器或XPath来定位数据所在的位置。

然后,使用合适的方法来从网页中提取所需的数据,并进行适当的处理和存储。

在编写完爬取代码之后,您可以运行爬取器并观察其工作情况。

您可以查看它是否按照您的预期进行爬取,并检查爬取到的数据是否准确无误。

如果爬取过程中出现问题,您可以根据报错信息和日志进行调试和改进。

最后,当您满意爬取结果后,您可以对获得的数据进行进一步的处理和分析。

这可能包括数据清洗、数据转换、数据可视化等操作,以使数据更具有实用价值。

总的来说,网页爬取器是一种功能强大的工具,可以帮助您从互联网上收集所需的数据。

通过选择合适的编程语言和库,并合理设置参数,您可以编写出高效而准确的爬取代码,并获得可靠的爬取结果。

请记住,在使用网页爬取器进行数据收集时,要遵守相关法律法规和网络道德规范,同时避免对网站造成不必要的负荷和影响。

webbrowser 用法

webbrowser 用法

一、webbrowser 的定义与作用webbrowser,即网页浏览器,是一种用于访问互联全球信息站网页的软件工具。

通过webbrowser,用户可以输入网页位置区域并访问网页内容,浏览器还可以展示各种网页元素,如文字、图片、视瓶和动画等。

由于其重要作用,webbrowser在现代社会中被广泛使用,成为人们日常生活中不可或缺的工具之一。

二、webbrowser 的基本使用方法在使用webbrowser时,我们通常需要了解一些基本的使用方法,以便更加高效地浏览网页内容。

1. 打开 webbrowser要打开webbrowser,只需在计算机桌面或程序菜单中找到已安装的浏览器图标,并双击打开即可。

常见的webbrowser包括Google Chrome、Mozilla Firefox、Microsoft Edge和Safari等。

用户可以根据自己的喜好和需求选择合适的浏览器。

2. 输入全球信息站在webbrowser的位置区域栏中输入网页的URL位置区域,即可打开相应的网页。

用户也可以利用webbrowser提供的搜索引擎功能,在搜索框中输入关键词进行网页搜索。

3. 浏览网页内容一旦打开了网页,用户可以通过滚动页面、点击信息或者进行搜索等操作来浏览网页内容。

webbrowser还提供了书签功能,用户可以将常用的网页添加到书签栏中,以便快速访问。

4. 下载和管理文件webbrowser允许用户在网页上下载各种文件,如文档、图片、音频和视瓶等。

用户可以在下载管理器中查看和管理已下载的文件。

5. 多标签浏览现代webbrowser支持多标签浏览功能,用户可以在同一个浏览器窗口中打开多个标签页,方便在不同页面之间进行切换和比较。

6. 清除浏览数据webbrowser还提供清除浏览数据的功能,用户可以清除浏览历史、缓存文件和 Cookie 等数据,以保护个人隐私并提升浏览速度。

三、webbrowser 的高级功能与技巧除了基本的浏览网页功能外,webbrowser还具有一些高级功能和技巧,可以帮助用户更好地利用浏览器。

使用webBrowser采集网页数据

使用webBrowser采集网页数据

using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Text.RegularExpressions;namespace ProWebBrowserCaiJi{public partial class Form1 : Form{private static int PageIndex = 0;private static int HasFetechPageIndex = 0;private static int type = 0;//采集类型0:水果1:蔬菜2:大田private static int FetechCurCount = 0;//当前页采集数量private static int FetechCount = 0;//采集数量public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){groupBox3.Focus();txtEndDate.Text = DateTime.Now.ToString("yyyy-MM-dd");}private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){string html;if (PageIndex == 0){return;}//取得页面html源码html = webBrowser1.Document.Body.InnerHtml;//if (!CompleteFlag)//{// lblMsg.Text = "正在采集:第" + PageIndex + " 页";//}switch (type){case 0://水果GetPriceAgrosg(html);break;case 1://蔬菜GetPriceVegnet(html);break;case 2://大田if (HasFetechPageIndex >= PageIndex){return;}HtmlElementCollection elems =webBrowser1.Document.GetElementsByTagName("div");bool flag = false;int i = 0;FetechCurCount = 0;foreach (HtmlElement elem in elems){if (elem.GetAttribute("className").Equals("price")){i++;if (!flag){HasFetechPageIndex = PageIndex;flag = true;}html = elem.InnerHtml;if (i == 1){continue;}if (GetPriceDaTian(html) == -100){lblMsg.Text = "大田作物价格数据采集完成,共采集" + FetechCount + " 条";PageIndex = 0;timDaTian.Stop();return;}}}if (flag){//已采集页lblMsg.Text = "大田采集完成:第" + PageIndex + " 页共" + FetechCurCount + " 个";if (FetechCurCount < 25){lblErr.Text += PageIndex + ",";}System.Threading.Thread.Sleep(1000);}break;}System.Threading.Thread.Sleep(1000);}///<summary>///价格行情-- 中国水果网///</summary>private void GetPriceAgrosg(string html){html = html.ToLower();NGJ.BLL.sys_Price bll = new NGJ.BLL.sys_Price();NGJ.Model.sys_Price model = new NGJ.Model.sys_Price();int startIndex = 0;int endIndex = 0;startIndex = html.IndexOf("<div id=price_btbj class=pri_list");if (startIndex < 0){return;}endIndex = html.IndexOf("</div>", startIndex + 10);html = html.Substring(startIndex, endIndex + 6 - startIndex);if (HasFetechPageIndex >= PageIndex){return;}//已采集页HasFetechPageIndex = PageIndex;startIndex = 0;endIndex = 0;string tmp = "";int index = 0;int i = 0;FetechCurCount = 0;while (true){startIndex = html.IndexOf("<li", endIndex);if (startIndex < 0){break;}endIndex = html.IndexOf("</li>", startIndex);if (endIndex < 0){continue;}tmp = html.Substring(startIndex, endIndex + 5 - startIndex);tmp = striphtml(tmp);tmp = tmp.Trim();index++;if (index <= 7){continue;}if (tmp == ""){continue;}i = index % 7;switch (i){case 1:model = new NGJ.Model.sys_Price();model.pagIndex = PageIndex;model.PriceDate = DateTime.Parse(tmp);model.type = 0;if (model.PriceDate < DateTime.Parse(txtEndDate.Text)){lblMsg.Text = "水果作物价格数据采集完成,共采集" + FetechCount + " 条";PageIndex = 0;timShuiGuo.Stop();return;}break;case 2:model.varieties = tmp;break;case 3:model.market = tmp;break;case 4:model.lowPrice = tmp;break;case 5:model.highPrice = tmp;break;case 6:model.avgPrice = tmp;break;case 0:model.unit = tmp;bll.Add(model);FetechCurCount++;FetechCount++;break;}}lblMsg.Text = "水果采集完成:第" + PageIndex + " 页共" + FetechCurCount + " 个";if (FetechCurCount < 25){lblErr.Text += PageIndex + ",";}System.Threading.Thread.Sleep(1000);}///<summary>///价格行情-- 中国蔬菜网////// /Price/List_p3.html//////</summary>private void GetPriceVegnet(string html){html = html.ToLower();NGJ.BLL.sys_Price bll = new NGJ.BLL.sys_Price();NGJ.Model.sys_Price model = new NGJ.Model.sys_Price();int startIndex = 0;int endIndex = 0;startIndex = html.IndexOf("<div class=pri_k>");if (startIndex < 0){return; ;}endIndex = html.IndexOf("</div>", startIndex + 10);html = html.Substring(startIndex, endIndex + 6 - startIndex);if (HasFetechPageIndex >= PageIndex){return;}//已采集页HasFetechPageIndex = PageIndex;startIndex = 0;endIndex = 0;string tmp = "";int index = 0;int i = 0;FetechCurCount = 0;while (true){startIndex = html.IndexOf("<span", endIndex);if (startIndex < 0){break;}endIndex = html.IndexOf("</span>", startIndex);if (endIndex < 0){continue;}tmp = html.Substring(startIndex, endIndex + 7 - startIndex);tmp = striphtml(tmp);tmp = tmp.Trim();index++;i = index % 8;switch (i){case 1:model = new NGJ.Model.sys_Price();model.pagIndex = PageIndex;model.type = 1;model.PriceDate = DateTime.Parse(tmp.Replace("[", "").Replace("]", ""));if (model.PriceDate < DateTime.Parse(txtEndDate.Text)){lblMsg.Text = "蔬菜作物价格数据采集完成,共采集" + FetechCount + " 条";PageIndex = 0;timer1.Stop();return;}break;case 2:model.varieties = tmp;break;case 3:model.market = tmp;break;case 4:model.lowPrice = tmp;break;case 5:model.highPrice = tmp;break;case 6:model.avgPrice = tmp;break;case 7:model.unit = tmp;bll.Add(model);FetechCurCount++;FetechCount++;break;}}lblMsg.Text = "蔬菜采集完成:第" + PageIndex + " 页共" + FetechCurCount + " 个";if (FetechCurCount < 25){lblErr.Text += PageIndex + ",";}System.Threading.Thread.Sleep(1000);}///<summary>///价格行情-- 中国大田网////// /Price/List?page=11//////</summary>private int GetPriceDaTian(string html){html = html.ToLower();NGJ.BLL.sys_Price bll = new NGJ.BLL.sys_Price();NGJ.Model.sys_Price model = new NGJ.Model.sys_Price();int startIndex = 0;int endIndex = 0;string tmp = "";int index = 0;int i = 0;while (true){startIndex = html.IndexOf("<div", endIndex);if (startIndex < 0){break;}endIndex = html.IndexOf("</div>", startIndex);if (endIndex < 0){continue;}tmp = html.Substring(startIndex, endIndex + 6 - startIndex);tmp = striphtml(tmp);tmp = tmp.Trim();index++;i = index % 5;switch (i){case 1:model = new NGJ.Model.sys_Price();model.pagIndex = PageIndex;model.lowPrice = "¥0.00";model.highPrice = "¥0.00";model.type = 2;model.PriceDate = DateTime.Parse(tmp);if (model.PriceDate < DateTime.Parse(txtEndDate.Text)){return -100;}break;case 2:model.varieties = tmp;break;case 3:model.market = tmp;break;case 4:model.avgPrice = tmp;break;case 0:model.unit = tmp;bll.Add(model);FetechCount++;FetechCurCount++;break;}}return 1;}///<summary>///前往///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnGo_Click(object sender, EventArgs e){if (txtUrl.Text.ToString().Trim() == ""){MessageBox.Show("请输入网址!");return;}lblMsg.Text = "加载中.....";webBrowser1.Navigate(txtUrl.Text.ToString().Trim());if (!webBrowser1.IsBusy){lblMsg.Text = "加载完成";}}///<summary>///蔬菜采集开始///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnStart_Click(object sender, EventArgs e) {type = 1;//采集类型0:水果1:蔬菜2:大田PageIndex = 0;lblMsg.Text = "蔬菜开始采集.....";lblErr.Text = "";FetechCount = 0;//采集数量HasFetechPageIndex = 0;//开始采集,初始化已采集页DeleteHasExist();//删除已有,重新采集timer1.Start();}///<summary>///大田采集开始///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnDaTian_Click(object sender, EventArgs e){type = 2;PageIndex = 0;lblMsg.Text = "大田开始采集.....";lblErr.Text = "";FetechCount = 0;//采集数量HasFetechPageIndex = 0;//开始采集,初始化已采集页DeleteHasExist();//删除已有,重新采集timDaTian.Start();}///<summary>///蔬菜///</summary>///<param name="sender"></param>///<param name="e"></param>private void timer1_Tick(object sender, EventArgs e){string strUrl = "/Price/List_p2.html";//浏览器加载完成if (!webBrowser1.IsBusy){PageIndex++;strUrl = "/Price/List_p" + PageIndex + ".html";//浏览器控件跳转到下一页投诉信息列表webBrowser1.Navigate(strUrl);System.Threading.Thread.Sleep(3000);}}///<summary>///大田///</summary>///<param name="sender"></param>///<param name="e"></param>private void timDaTian_Tick(object sender, EventArgs e){string strUrl = "/Price/List?page=11";//浏览器加载完成if (!webBrowser1.IsBusy){PageIndex++;strUrl = "/Price/List?page=" + PageIndex;//浏览器控件跳转到下一页投诉信息列表webBrowser1.Navigate(strUrl);System.Threading.Thread.Sleep(3000);}}///<summary>///水果///</summary>///<param name="sender"></param>///<param name="e"></param>private void timShuiGuo_Tick(object sender, EventArgs e){string strUrl = "/Price/List.html?page=1&beginYear=" + DateTime.Now.Year + "&beginMonth=" + DateTime.Now.Month + "&beginDay=" + DateTime.Now.Day + "&endYear=" + DateTime.Now.Year + "&endMonth=" + DateTime.Now.Month + "&endDay=" + DateTime.Now.Day + "&cateName=&MID=0";//浏览器加载完成if (!webBrowser1.IsBusy){PageIndex++;strUrl = "/Price/List.html?page=" + PageIndex;//浏览器控件跳转到下一页投诉信息列表webBrowser1.Navigate(strUrl);System.Threading.Thread.Sleep(3000);}}///<summary>///蔬菜///</summary>///<param name="sender"></param>///<param name="e"></param>private void lkShuCai_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){txtUrl.Text = "/Price/List.html";webBrowser1.Navigate(txtUrl.Text.ToString().Trim());}///<summary>///大田///</summary>///<param name="sender"></param>///<param name="e"></param>private void lkDaTian_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){txtUrl.Text = "/Price/List";webBrowser1.Navigate(txtUrl.Text.ToString().Trim());}///<summary>///水果网///</summary>///<param name="sender"></param>///<param name="e"></param>private void lkShuiGuo_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {txtUrl.Text = "/Price/List.html";webBrowser1.Navigate(txtUrl.Text.ToString().Trim());}///<summary>///水果///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnShuiGuo_Click(object sender, EventArgs e){type = 0;//采集类型0:水果1:蔬菜2:大田PageIndex = 0;lblMsg.Text = "水果开始采集.....";lblErr.Text = "";FetechCount = 0;//采集数量HasFetechPageIndex = 0;//开始采集,初始化已采集页DeleteHasExist();//删除已有,重新采集timShuiGuo.Start();}///<summary>///删除已有,重新采集///</summary>private void DeleteHasExist(){NGJ.BLL.sys_Price bll = new NGJ.BLL.sys_Price();bll.Delete(txtEndDate.Text, type);}///<summary>///补采蔬菜///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnBuCai_Click(object sender, EventArgs e){type = 1;lblMsg.Text = "蔬菜补采开始.....";lblErr.Text = "";BuCai();}///<summary>///补采大田///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnBuCaiDT_Click(object sender, EventArgs e){type = 2;lblMsg.Text = "大田补采开始.....";lblErr.Text = "";BuCai();}///<summary>///补采水果///</summary>///<param name="sender"></param>///<param name="e"></param>private void btnBuCaiSG_Click(object sender, EventArgs e){type = 0;lblMsg.Text = "水果补采开始.....";lblErr.Text = "";BuCai();}private void BuCai(){PageIndex = int.Parse(txtYeMa.Text.ToString().Trim());NGJ.BLL.sys_Price bll = new NGJ.BLL.sys_Price();bll.Delete(txtEndDate.Text, type, PageIndex);HasFetechPageIndex = 0;//补采重设已采集页string strUrl = "";switch (type){case 0:strUrl = "/Price/List.html?page=" + PageIndex;break;case 1:strUrl = "/Price/List_p" + PageIndex + ".html";break;case 2:strUrl = "/Price/List?page=" + PageIndex;break;}//浏览器控件跳转到下一页投诉信息列表webBrowser1.Navigate(strUrl);System.Threading.Thread.Sleep(3000);}///<summary>///去除所有HTML标记///</summary>///<param name="strhtml"></param>///<returns></returns>private static string striphtml(string strhtml){string stroutput = strhtml;Regex regex = new Regex(@"<[^>]+>|</[^>]+>");stroutput = regex.Replace(stroutput, "");return stroutput;}} }。

Excel如何从网站获取数据

Excel如何从网站获取数据

Excel如何从⽹站获取数据
有时候我们在制作Excel表格时,很多数据的来源可能是⽹上来的,那就需要从⽹站⾥⾯下载数据给我们使⽤,或者需要⾃⼰⼿动⾃⼰⼀个个对照输⼊……但是这样都太⿇烦了,今天教⼤家⼀个⽅法,可以快速地从⽹站上来获取⾃⼰需要的数据哦!喜欢记得收藏啦!
操作步骤:
1.⾸先我们打开⼀个⽹站,找到⾃⼰想要的数据,先把⽹站的链接复制下来。

这⾥我们选择的是个⼈所得税税率表,想把⽹页⾥表格的内容都抓取下来。

2.然后打开你的Excel表格,然后点击【数据】-【⾃⽹站】,然后会弹出⼀个【新建web】查询对话框。

然后在地址栏中粘贴⾃⼰刚刚复制的⽹站连接。

然后选择【转到】,这样就会⾃动跳转到⽹站的数据界⾯。

3.然后点击【新建Web查询】对话框中想要表格的【箭头】按钮,然后再点击右下⾓的【导⼊】。

经过这个操作之后,我们需要的数据就会添加到Excel表格中来。

4.当你要导⼊数据时,可以选择数据的放置位置,或者是数据的起始位置,也可以新建⼯作表,选择完毕之后你点击【确定】即可。

这样你就可以看到刚才⽹站⾥的数据都⼀次性添加到你的Excel表格⾥了。

注意如果数据量较⼤在导⼊的时候可能会⽐较慢,不过最后都是可以轻松把⽹站的数据给抓取下来滴!
最后可以通过【套⽤表格样式】你再把表格稍微给美化⼀下,就ok啦~
最终的效果:
这⾥再放⼀个动图演⽰给⼤家看看,不明⽩可以在看看这⾥哦!
好啦~以上就是关于怎么从⽹页抓取数据的⼩技巧了,经常需要在⽹上收集数据的朋友,希望可以对你有所帮助,有⽤的话欢迎点赞、转发、收藏哦!笔芯!。

你了解Excel中的Web查询吗?

你了解Excel中的Web查询吗?

你了解Excel中的Web查询吗?
可能大家对Excel中的Web查询了解不是很清楚,有些人根本不知道它的作为,现在来讲述一些关于Web的作用。

保持Excel工作表总是最新Web页上经常包含适合在Excel中进行分析的信息,例如,可以在Excel中使用直接从Web页上获取的信息分析股票报价。

但如果你需要经常更新信息就必须借助Web页上的最新信息。

现在Excel 2002可以用可刷新Web查询简化这个任务来创建新的可刷新Web查询,方法如下: 在浏览器中浏览要查询数据的Web页,把数据复制并粘贴到Excel工作表中。

在粘贴的数据下方将出现一个粘贴选项智能标记,单击粘贴选项智能标记右边的箭头,再单击创建可刷新的Web查询,在新建Web查询对话框中,点击你想要查询的数据表前面的黄色箭头,单击导入。

在Excel中可以手动或自动刷新这个数据。

手动刷新方法如下:在外部数据工具栏上,单击数据区域属性按钮,在刷新控制下面选中你想要的选项的复选框。

注意:当你从Web站点获取数据时,可能会丢失一些格式或内容,像脚本、gif图像或单个单元中的数据列表。

Web Browser控件终端自动采集数据的方法与实践

Web Browser控件终端自动采集数据的方法与实践

不同类型的客户编码为 关的客户贷款数据 按贷款 期限、贷款币种等字段导
入 E cl 件 中;自动 分 类 汇 总 并 形 成 报 表 , 个 过 程 无 需 人 x e文 整
载入原有业务系统首负 自动填写用户信息 控制鼠标单击
。 一
I l l l 燃 两 黢 两
W s 控件终端 e B r rw b o e 自动采集数 据的 方法 与实践
■文 / 中国人 民银行 北海 市中 心支行 中国人 民银行 海 口 中心支行 蒋 利 唐大 林

前,各银行的业务系统广泛采用集中数据库管理模式, 容易 出错 ,效率很低 。 考虑到上述需 求, 笔者利用We rwsr b B o e 控件开发 了客 户数据 自动采集程序 ( 以下简称 采集程 序 ) 完善 了原有 系统 , 的功能 ,满足 了工作需要 ,完成 了工 作任务 。 采集程序主要 利用 We rwsr b B o e 控件 , 目的是为 了能够
户批量查询 客户贷款 数据 , 采集速度 由原来的5 分钟/ 缩短 户
1分析 网页
获 取 贷 款余 额

至1 分钟/户 , 能 自动分类 汇总 , 且 整个过程无 需工 作人员任
——
贷 款余 额是 否为 零 ,

何手工操作 ,保 证了采集工作的准确 、便捷 ,大大提高 了工
1控 制 鼠标 单 击
贷款 余 额
链接
作速度和质量 ,可以很大程度上解决手工操作业务 系统准确 率低 、操作速度慢 等难题。采集程序可 以弥补原业务系统 的 不足 ,有利于对 原业 务系统的功能做进一步拓展 ,有利于终 端用户 对原业 务系 统提供 的数据直 接进 行加工 整理 。W e b

delphiWebBrowser的使用方法详解(四)

delphiWebBrowser的使用方法详解(四)

delphi WebBrowser 的使用方法详解(四)delphi WebBrowser 的使用方法详解(四) -webbrowser 轻松实现自动填表分类:Delphi Webbrowser TembeddedWB 2013-11-01 17:02 220 人阅读评论(0) 收藏举报目录(?)[+]webbrowser 轻松实现自动填表步骤如下:第一步:获取网页调用Webbrowser 的Navigate 系列函数。

等待网页装载完成,得到document 对象。

在调用webBrowser.Document 之前,请确保Webbrowser 网页装载完成,可以通过Webbrowser 的DocumentCompleted 事件进行监视。

小技巧先指定一个变量步骤如下:第一步:获取网页调用Webbrowser 的Navigate 系列函数。

等待网页装载完成,得到document 对象。

在调用webBrowser.Document 之前,请确保Webbrowser 网页装载完成,可以通过Webbrowser 的DocumentCompleted 事件进行监视。

小技巧先指定一个变量:IsCompleted在调用Webbrowser 的Navigate ,Refresh 系列函数之前,将IsCompleted 设为false。

在DocumentCompleted 事件中,如果ReadyState 为plete(值为4),则设IsCompleted 为true.调用webBrowser.Document 之前对IsCompleted 进行判断。

如果不为true,则延时循环等待,直到IsCompleted被设为true.第二步:设置网页元素数据确保得到document 对象之后,通过GetElementById 获取网页元素,如:HtmlElement user = webBrowser.Document.GetElementById("user"); HtmlElement password =webBrowser.Document.GetElementById("password"); 设置网页元素值:user.InnerText = "myname"; password.InnerText = "123456";小技巧作用SetAttribute 设置下拉框,复选框,多选框数据下拉框:secret.SetAttribute("value", "question1"); 复选框rememberme.SetAttribute("Checked", "True"); 多选框cookietime.SetAttribute("checked", "checked");当然,在SetAttribute 之前,也可以用GetAttribute 取相关的属性先进行判断,再根椐需要进行设置。

c#winformwebBrowser爬取数据

c#winformwebBrowser爬取数据

c#winformwebBrowser爬取数据int index=0;private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e){if (webBrowser1.ReadyState == plete)//是否完全加载完成{textBox2.AppendText("就绪.....\r\n");if (index == 0){if (e.Url.ToString() == webBrowser1.Url.ToString()){this.cobURL.Text = this.webBrowser1.Document.Url.ToString();this.TabText.Text = this.webBrowser1.DocumentTitle;HtmlDocument hd = webBrowser1.Document;HtmlElement he = hd.GetElementsByTagName("input").GetElementsByName("keywords")[0];he.InnerText = this.textBox6.Text.Trim().ToString();//你要查的内容HtmlElement bt = webBrowser1.Document.All["header-search-button"];bt.InvokeMember("click");//主页⾯,触发点击事件,根据你要查的内容去进⼊⼦页⾯textBox2.AppendText("正在进⼊⼦页⾯.....\r\n");index++;}}else if (index == 1){textBox2.AppendText("进⼊"+ e.Url.ToString() + "\r\n");if (e.Url.ToString() == webBrowser1.Url.ToString()){this.cobURL.Text = this.webBrowser1.Document.Url.ToString();this.TabText.Text = this.webBrowser1.DocumentTitle;HtmlDocument hd = webBrowser1.Document;if (hd.GetElementById("DatasheetsTable1")==null){textBox2.AppendText("该地址未能找到所需数据.....\r\n");textBox2.AppendText("获取结束.....\r\n");webBrowser1.DocumentCompleted -= new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted); index = 0;return;}string ceshi= hd.GetElementById("DatasheetsTable1").FirstChild.OuterText.ToString();string[] sArray = ceshi.Split(new string[] { "\r\n"}, StringSplitOptions.RemoveEmptyEntries);string bz= sArray[1].Replace("c数据表头", "");//根据情况处理bz= bz.Trim().ToString();//获取数据ctextBox3.Text = bz;string ceshi1 = hd.GetElementById("SpecificationTable1").FirstChild.OuterText.ToString();string[] sArray1 = ceshi1.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);string fz = sArray1[7].Replace("a数据表头", "");fz = fz.Trim().ToString();//获取数据atextBox4.Text = fz;string qjfz = sArray1[8].Replace("b数据表头", "");qjfz = qjfz.Trim().ToString();//获取数据btextBox5.Text = qjfz;index = 0;textBox2.AppendText("获取结束.....\r\n");webBrowser1.DocumentCompleted -= new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted); }}}}private void button7_Click(object sender, EventArgs e){if (textBox6.Text.ToString()!=""){textBox2.Clear();textBox3.Text = "";textBox4.Text = "";textBox5.Text = "";textBox2.AppendText("正在获取中.....\r\n");this.webBrowser1.Url = new Uri("地址");this.webBrowser1.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.webBrowser1_DocumentCompleted);}}界⾯⼤致,webBrowser隐藏了,把webBrowser的ScriptErrorsSuppressed要设置为True,负责会弹script错误。

Excel希望狼版主教教我们读取网页数据方面知识

Excel希望狼版主教教我们读取网页数据方面知识

我收集的资料,供你参考近期写了一段程序:从网上下载数据,写入数据库,查询、分析、打印。

找了很多的资料,现作一回顾总结,本篇主要写网页数据下载与控制。

(以下均为本人的一些心得,写的不对的,请各位师傅指正。

希望本文能对和我一样菜的朋友有一些帮助。

)一、概述及感谢二、Maxthon的使用三、网页关键字(录入、按钮、数据)解读四、POST、GET与NAME、V ALUE五、使用WebBrowser六、使用IE七、查询结果是新弹出窗口的控制八、使用POST方法九、使用EXCEL获取网页数据十、例:利用webbrowser获得网页数据附件一、XmlHttp对象用法示例与说明一、概述及感谢需要用到网页控制的方面,大致概括一下为:1、程序中需要嵌入一个网页,例如:天气预报。

2、需要从网上下载数据,写入到本地数据库中。

特别需要感谢Winland对我的指导。

二、Maxthon的使用无论哪方面的应用,首要的是找到网址(也许是废话)。

以Winland的天气预报为例,假如我的程序需要这样一个东西,我该如何下爪:1、打开2、点击“天气预报”,打开:3、查一个城市试试,此时结果找到了,但网址没变。

4、点击Maxthon的viewpage。

5、在“框架”中,发现一个“内嵌框架”,点击打开。

发现原来天气预报的网址为:6、下一步,在我们自己的程序中就可以使用这个网址,直接来查询了。

综上所述,通过Maxthon,我们可以很方便地找到我们所需要的真正的网址。

在viewpage中还有一个“表单”,里面很清楚地显示了Name,method,以及Action。

我理解这个Action就是“结果网页”的网址的后半部分(不知对不对?)。

(在网页的表单里面Action是目标地址,就是处理这些递交内容的服务器端脚本。

如果Action为空的话,就是当前文件。

)三、网页关键字(录入、按钮、数据)解读<% 和%> ASP脚本片断的开始和结束。

在<%和%>标签之间的脚本代码,在主页传递给用户浏览器之前会在服务器上执行。

webtable表中单选框、多选框获取数值、index、按顺序选择

webtable表中单选框、多选框获取数值、index、按顺序选择

‘单选框Dim num,num1set num1=Browser("德清发改委项目建设综控系统").Page("德清发改委项目建设综控系统").Frame("main").WebTable("岗位名称")set num=Browser("德清发改委项目建设综控系统").Page("德清发改委项目建设综控系统").Frame("main").WebRadioGroup("record:_flag")hang=num1.RowCount '获取webtable行数For i=2 to hangnr=num1.GetCellData(i,2) '获取webtable第i行、第2列的值,用GetCellData函数'print "获取的第一列内容=:"&nr'xk=num.GetROProperty ("selected item index")'获取单选框选中的indexBrowser("德清发改委项目建设综控系统").Page("德清发改委项目建设综控系统").Frame("main").WebRadioGroup("record:_flag").Select nr '单选框选择数据,nr是变量,在上一行中被赋值xk=num.GetROProperty ("selected item index")'获取单选框选中的index'print "获取被选择单选框index=:"&xknr1=num.GetROProperty ("value") '获取单选框被选择的内容'print "单选框被选择的内容为=:"&nr1print "获取的第"&i-1&"行内容=:"&nr&" 获取被选择单选框index=:"&xk&" "&"单选框被选择的内容为=:"&nr1Next‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’‘多选框Dim abcset abc=Browser("软件应用框架").Page("软件应用框架").Frame("Frame").WebTable("新闻标题")hang=abc.RowCount '行lie=abc.ColumnCount(1) '列For i=2 to hang' 行For j=2 to lie '列flog=0nr=abc.GetCellData(i,j)If nr=" " Then '如果查询出的内容为空Exit for' 退出for 循环elsek=k+" "+nr '将列表中的一行内容复制给kDim xuanzhongset xuanzhong=abc.ChildItem (i,1,"webcheckbox",0) '查找选择框,第i行,第1列webcheckbox 是控件类别If flog=0 Thenxuanzhong.set "on"flog=1'else' xuanzhong.set "off"' flog=0End IfEnd IfNextprint kk=""Next。

在中WebBrowser加载Excel后获取excel对象

在中WebBrowser加载Excel后获取excel对象

标题: 在中WebBrowser加载Excel后获取excel对象- 邓春光 2010-04-20 11:11 阅读:59- 评论:0 | 添加评论 | 返回↓在最新的Visual Studio 2005中,为我们提供了一个WebBrowser的封装控件,这个控件隐藏了底层的axWebBrowser控件,我们就利用WebBrowser控件来完成我们的Excel等ActiveDocument的嵌入和操作。

在此之前,你需要将Office的.Net库安装到你的机器上。

1.在你的工具栏上选择WebBrowser控件,将其放到你的Form上2.在Form上增加一个控件来使其加载一个Excel文件,如下:Button的事件处理程序:privatevoidbutton1_Click_1(objectsender, EventArgs e){stringstrFileName =@"d:\a.xls";Object refmissing = System.Reflection.Missing.Value;this.webBrowser1.Navigate(strFileName);objectaxWebBrowser =this.webBrowser1.ActiveXInstance;}3.增加WebBrowser的DocumentComplete事件处理程序privatevoidwebBrowser1_DocumentCompleted_1(objectsender, WebBrowserDocumentCompletedEventArgs e){Object refmissing = System.Reflection.Missing.Value;object[] args =newobject[4];args[0] = SHDocVw.OLECMDID.OLECMDID_HIDETOOLBARS;args[1] = SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER;args[2] = refmissing;args[3] = refmissing;objectaxWebBrowser =this.webBrowser1.ActiveXInstance;axWebBrowser.GetType().InvokeMember("ExecWB",BindingFlags.InvokeMethod,null, axWebBrowser, args);objectōApplication = axWebBrowser.GetType().InvokeMember("Document",BindingFlags.GetProperty,null, axWebBrowser,null);Excel.Workbook wbb = (Excel.Workbook) oApplication;Excel.ApplicationClass excel = wbb.ApplicationasExcel.ApplicationClass;Excel.Workbook wb = excel.Workbooks[1];Excel.Worksheet ws = wb.Worksheets[1]asExcel.Worksheet; ="Verdana";ws.Cells.Font.Size = 14;ws.Cells.Font.Bold =true;Excel.Range range = ws.Cells;Excel.Range ōCell = range[10, 10]asExcel.Range;oCell.Value2 ="你好";}这里要注意,WebBrowser加载Excel文档后,并不显示工具栏,为此我们需要使用高级一点的技术,通过反射调用底层的方法来实现,首先我们需要找到WebBrowser封装的AxWebBrowser控件。

利用WebBrowser读取网页中表格的数据

利用WebBrowser读取网页中表格的数据

利用WebBrowser读取网页中表格的数据unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, MSHTML, StdCtrls, OleCtrls, SHDocVw;typeTForm1 = class(TForm)Button1: TButton;WebBrowser1: TWebBrowser;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}function GetHtmlT ableCell(aTable: IHTMLTable; aRow, aCol: Integer): IHTMLElement;varRow: IHTMLTableRow;beginResult := nil;if aTable = nil then Exit;if aTable.rows = nil then Exit;Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;if Row = nil then Exit;Result := Row.cells.item(aCol, aCol) as IHTMLElement;end;function GetHtmlTable(aDoc: IHTMLDocument2; aIndex: Integer): IHTMLTable;varlist: IHTMLElementCollection;beginResult := nil;if aDoc = nil then Exit;if aDoc.all = nil then Exit;list := aDoc.all.tags('table') as IHTMLElementCollection;if list = nil then Exit;Result := list.item(aIndex, aIndex) as IHTMLTable;end;function GetWebBrowserHtmlTableCellText(const AWebBrowser: TWebBrowser;const TableIndex, RowIndex, ColIndex: Integer;var ResValue: string): Boolean;varDocintf: IHTMLDocument2;tblintf: IHTMLTable;node: IHTMLElement;beginResValue := ' ';tf := AWebBrowser.Document as IHTMLDocument2;tblintf := GetHtmlT able(tf, TableIndex);node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);Result := node <> nil;if Result thenResValue := Trim(node.innerText);end;function GetHtmlT ableRowHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;varRow: IHTMLTableRow;beginResult := nil;if aTable = nil then Exit;if aTable.rows = nil then Exit;Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;if Row = nil then Exit;Result := Row as IHTMLElement;end;function GetWebBrowserHtmlTableCellHtml(const AWebBrowser: TWebBrowser;const TableIndex, RowIndex, ColIndex: Integer;var ResValue: string): Boolean;varDocintf: IHTMLDocument2;tblintf: IHTMLTable;node: IHTMLElement;beginResValue := ' ';tf := AWebBrowser.Document as IHTMLDocument2;tblintf := GetHtmlT able(tf, TableIndex);node := GetHtmlTableCell(tblintf, RowIndex, ColIndex);Result := node <> nil;if Result thenResValue := Trim(node.innerHTML);end;function GeHtmlTableHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;varRow: IHTMLTableRow;beginResult := nil;if aTable = nil then Exit;if aTable.rows = nil then Exit;Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;if Row = nil then Exit;Result := Row as IHTMLElement;end;function GetWebBrowserHtmlT ableHtml(const AWebBrowser: TWebBrowser;const TableIndex, RowIndex: Integer;var ResValue: string): Boolean;varDocintf: IHTMLDocument2;tblintf: IHTMLTable;node: IHTMLElement;beginResValue := ' ';tf := AWebBrowser.Document as IHTMLDocument2;tblintf := GetHtmlT able(tf, TableIndex);node := GeHtmlTableHtml(tblintf, RowIndex);Result := node <> nil;if Result thenResValue := node.innerHtml;end;procedure TForm1.FormCreate(Sender: TObject);beginWebBrowser1.Navigate('H:\ReadTable\00.html');end;procedure TForm1.Button1Click(Sender: TObject);varResValue: string;beginif GetWebBrowserHtmlTableCellText(WebBrowser1, 0, 0, 0, ResValue) thenbeginShowMessage(ResValue);end elsebeginShowMessage('指定的表格不存在 '); end;end;end.。

Javaweb获取表单数据的多种方式

Javaweb获取表单数据的多种方式

Javaweb获取表单数据的多种⽅式Javaweb获取表单数据的⼏种⽅式⼀、通过键值对的形式获取表单数据getParameter(String name):通过key,返回⼀个value。

getParameterValues(String name):通过key返回⼀个string数组(多个值)getParameterNames():返回form表单中的所有key值。

下⾯介绍通过键值对获取form表单数据的数据的⽅法:@WebServlet({ "/FormServlet", "/form" })public class FormServlet extends HttpServlet {private static final long serialVersionUID = 1L;public FormServlet() {super();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json;charset=utf-8");PrintWriter out = response.getWriter();Enumeration<String> paramNames = request.getParameterNames();while (paramNames.hasMoreElements()) {String name = paramNames.nextElement();String[] values = request.getParameterValues(name);if(values!=null && values.length>0){StringBuilder builder = new StringBuilder();for (int i = 0; i < values.length; i++) {builder.append(values[i]+" ");}out.println(name+" : "+builder.toString());}}}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response);}}form表单:<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title></head><body><form action="/TomcatDemo/form" method="post">⽤户名<input type="text" name="username"/><br/>密码 <input type="password" name="password"/><br/>性别 <input type="radio" name="sex" value="male" checked="checked"/>男<input type="radio" name="sex" value="female"/>⼥<br/>爱好 <input type="checkbox" name="hobby" value="basketball"/>篮球<input type="checkbox" name="hobby" value="football"/>⾜球<input type="checkbox" name="hobby" value="game"/>游戏<input type="checkbox" name="hobby" value="media"/>电影<br/>城市 <select name="city"><option value="bj">北京</option><option value="sh">上海</option><option value="sz">深圳</option><option value="hz">杭州</option></select><br/><input type="submit" value="注册"/><input type="submit" value="登⼊"/><br/></form></body></html>⼆、通过Map的形式获取表单数据getParameterMap():获取form表单的数据,以map的格式封装起来⽰例:@WebServlet({ "/FormServlet", "/form" })public class FormServlet extends HttpServlet {private static final long serialVersionUID = 1L;public FormServlet() {super();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json;charset=utf-8");PrintWriter out = response.getWriter();User user = new User();out.println("获取表单数据之前:"+user.toString());Map<String,String[]> map = request.getParameterMap();for (Map.Entry<String, String[]> m : map.entrySet()) {String name = m.getKey();String[] values = m.getValue();//属性描述器:表⽰JavaBean类通过存储器导出⼀个属性PropertyDescriptor pd=null;try {pd = new PropertyDescriptor(name, User.class);} catch (IntrospectionException e) {e.printStackTrace();}if (values!=null&& pd !=null) {Method setter = pd.getWriteMethod();try {if (values.length==1) {setter.invoke(user, values[0]);}else {setter.invoke(user, (Object)values);}} catch (IllegalAccessException e) {e.printStackTrace();} catch (IllegalArgumentException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}}}out.println("获取表单数据之后:"+user.toString());}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response);}}PropertyDescriptor的使⽤,User类public class User {private String username;//属性名称需要和表单数据中的name值保持⼀致private String password;private String sex;private String[] hobby;private String city;...//set get⽅法省略}三、通过第三⽅jar包获取封装表单数据使⽤第三⽅jar包:commons-beanutils-1.8.3.jar@WebServlet({ "/FormServlet", "/form" })public class FormServlet extends HttpServlet {private static final long serialVersionUID = 1L;public FormServlet() {super();}protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/json;charset=utf-8");PrintWriter out = response.getWriter();User user = new User();out.println("获取表单数据之前:"+user.toString());try {//通过第三⽅jar包处理BeanUtils.populate(user, request.getParameterMap());} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();}out.println("获取表单数据之后:"+user.toString());}protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response);}}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。

【26期VBA】网页数据提取WebBrowser--ldy888

【26期VBA】网页数据提取WebBrowser--ldy888

10.85 10.88 10.8 11.15 11 11.18 11.16 9.13 8.53 8.75 8.57 8.24 8.08 8.13 8.19 8 8.2 8.32 8.04 8 7.76 7.89 7.67 7.66 7.2 7.11 7.15 7.09 7.25 7.4 7.57 7.4 7.3 7.22 7.56 7.65 7.68 7.57 7.23 7.32 7.25
2007-02-06 2007-02-05 2007-02-02 2007-02-01 2007-01-31 2007-01-30 2007-01-29 2007-01-26 2007-01-25 2007-01-24 2007-01-23 2007-01-22 2007-01-19 2007-01-18 2007-01-17 2007-01-16 2007-01-15 2007-01-12 2007-01-11 2007-01-10 2007-01-09 2007-01-08 2007-01-05 2007-01-04 2006-12-29 2006-12-28 2006-12-27 2006-12-26 2006-12-25 2006-12-22 2006-12-21 2006-12-20 2006-12-19 2006-12-18 2006-12-15 2006-12-14 2006-12-13 2006-12-12 2006-12-11 2006-12-08 2006-12-07 2006-12-06 2006-12-05 2006-12-04 2006-12-01 2006-11-30 2006-11-29
股票代码 日 期 2007-06-29 2007-06-28 2007-06-27 2007-06-26 2007-06-25 2007-06-22 2007-06-21 2007-06-20 2007-06-19 2007-06-18 2007-06-15 2007-06-14 2007-06-13 2007-06-12 2007-06-11 2007-06-08 2007-06-07 2007-06-06 2007-06-05 2007-06-04 2007-05-31 2007-05-30 2007-05-29 2007-05-28 2007-05-25 2007-05-24 2007-05-23 2007-05-22 2007-05-21 2007-05-18 2007-05-17 2007-05-16 2007-05-15 2007-05-14 2007-05-11 2007-05-10 2007-05-09 2007-05-08 2007-04-30 2007-04-27 2007-04-26 2007-04-25 2007-04-24 2007-04-23 2007-04-20
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

利用WebBrowser读取网页中表格的数据
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MSHTML, StdCtrls, OleCtrls, SHDocVw;type TForm1 = class(TForm)
Button1: TButton;
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}function GetHtmlTableCell(aTable: IHTMLTable; aRow, aCol: Integer): IHTMLElement;
var
Row: IHTMLTableRow;begin
Result := nil;
if aTable = nil then Exit;
if aTable.rows = nil then Exit;
Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
if Row = nil then Exit;
Result := Row.cells.item(aCol, aCol) as IHTMLElement; end;function GetHtmlTable(aDoc: IHTMLDocument2; aIndex: Integer): IHTMLTable;
var
list: IHTMLElementCollection;
begin
Result := nil;
if aDoc = nil then Exit;
if aDoc.all = nil then Exit;
list := aDoc.all.tags('table') as IHTMLElementCollection; if list = nil then Exit;
Result := list.item(aIndex, aIndex) as IHTMLTable; end;function GetWebBrowserHtmlTableCellText(const AWebBrowser: TWebBrowser;
const TableIndex, RowIndex, ColIndex: Integer;
var ResValue: string): Boolean;
var
Docintf: IHTMLDocument2;
tblintf: IHTMLTable;
node: IHTMLElement;
begin
ResValue := ' ';
docintf := AWebBrowser.Document as IHTMLDocument2;
tblintf := GetHtmlTable(docintf, TableIndex);
node := GetHtmlTableCell(tblintf, RowIndex, ColIndex); Result := node &lt;&gt; nil;
if Result then
ResValue := Trim(node.innerText);
end;function GetHtmlTableRowHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;
var
Row: IHTMLTableRow;
begin
Result := nil;
if aTable = nil then Exit;
if aTable.rows = nil then Exit;
Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
if Row = nil then Exit;
Result := Row as IHTMLElement;
end;function GetWebBrowserHtmlTableCellHtml(const AWebBrowser: TWebBrowser;
const TableIndex, RowIndex, ColIndex: Integer;
var ResValue: string): Boolean;
var
Docintf: IHTMLDocument2;
tblintf: IHTMLTable;
node: IHTMLElement;
begin
ResValue := ' ';
docintf := AWebBrowser.Document as IHTMLDocument2;
tblintf := GetHtmlTable(docintf, TableIndex);
node := GetHtmlTableCell(tblintf, RowIndex, ColIndex); Result := node &lt;&gt; nil;
if Result then
ResValue := Trim(node.innerHTML);
end;function GeHtmlTableHtml(aTable: IHTMLTable; aRow: Integer): IHTMLElement;
var
Row: IHTMLTableRow;
begin
Result := nil;
if aTable = nil then Exit;
if aTable.rows = nil then Exit;
Row := aTable.rows.item(aRow, aRow) as IHTMLTableRow;
if Row = nil then Exit;
Result := Row as IHTMLElement;
end;function GetWebBrowserHtmlTableHtml(const AWebBrowser: TWebBrowser;
const TableIndex, RowIndex: Integer;
var ResValue: string): Boolean;
var
Docintf: IHTMLDocument2;
tblintf: IHTMLTable;
node: IHTMLElement;
begin
ResValue := ' ';
docintf := AWebBrowser.Document as IHTMLDocument2;
tblintf := GetHtmlTable(docintf, TableIndex);
node := GeHtmlTableHtml(tblintf, RowIndex);
Result := node &lt;&gt; nil;
if Result then
ResValue := node.innerHtml;
end;procedure TForm1.FormCreate(Sender: TObject); begin
WebBrowser1.Navigate('H:\ReadTable\00.html'); end;procedure TForm1.Button1Click(Sender: TObject); var
ResValue: string;
begin
if GetWebBrowserHtmlTableCellText(WebBrowser1, 0, 0, 0, ResValue) then
begin
ShowMessage(ResValue);
end else
begin
ShowMessage('指定的表格不存在');
end;
end;end.。

相关文档
最新文档