【发布时间】:2018-06-28 22:16:54
【问题描述】:
我正在尝试抓取页面:https://www.investing.com/equities/statoil-technical
我想要实现的是点击 5 分钟、15 分钟、30 分钟等按钮并阅读点击后发生变化的枢轴点表。
我尝试了许多不同的方法。 System.Windows.Forms.Browser、ChromiumWebBrowser (Cef) 和现在的带有 JavaScript 的 ChromiumWebBrowser。
像这样:
script = " var ul = document.getElementById('pairSublinksLevel1'); " +
" var items = ul.getElementsByTagName('li'); " +
" var Financials = 0; " +
// Find and click the Financials Botton
" for (var o = 0; o < items.length; o++) " +
" { " +
" if (items[o].textContent = 'Financials') {" +
" Financials = o;}" +
" } " +
" items[Financials].click() ; " +
// should I set " setTimeout(function(){}, 3000); " ?
" var lis = document.getElementById('pairSublinksLevel1').getElementsByTagName('li'); " +
" var TechnicalAnalysis = 0; " +
// Find and click the Technical Analysis sub menu
" for (var o = 0; o < lis.length; o++) " +
" { " +
" if (lis[o].textContent = 'Technical Analysis') {" +
" TechnicalAnalysis = o;}" +
" } " +
" lis[TechnicalAnalysis].click();" +
// should I set " setTimeout(function(){}, 3000); " ?
// Get the bottons ( 5mins, 15mins, 30mins etc)
" var TimePeriods = document.getElementById('timePeriodsWidget').getElementsByTagName('li'); " +
" TimePeriods[5].click(); " +
// should I set " setTimeout(function(){}, 3000); " ?
" var x = document.getElementById('curr_table'); " +
" var xHTML= x.innerHTML ;";
var task = LocalBrowser.EvaluateScriptAsync(script, timeout);
task.Wait();
问题是,当我将“ TimePeriods[5].click(); 更改为按钮 3 或 1 或其他任何内容时,xHTML 不会改变。
我已经在 DOM 中尝试过。我在浏览器中试过。 我被困住了。
有人可以提示我正确的方向吗? 向我展示如何点击 LI :
<ul class="tabsBoxSubMenu techStudiesTabsSubMenu innerPage " id="timePeriodsWidget" data-view="normal">
<li pairid="376" data-period="300" class="first">
<li pairid="376" data-period="900" class="">
<li pairid="376" data-period="1800" class="">
<li pairid="376" data-period="3600" class="selected ">
<li pairid="376" data-period="18000" class="">
<li pairid="376" data-period="86400" class="">
<li pairid="376" data-period="week" class="">
<li pairid="376" data-period="month" class="">
</ul>
并获得
<table class="genTbl closedTbl crossRatesTbl" id="curr_table">
<thead>
<tr>
<th class="first left noWrap">Name</th>
<th class="noWrap">S3</th>
<th class="noWrap">S2</th>
<th class="noWrap">S1</th>
<th class="noWrap">Pivot Points</th>
<th class="noWrap">R1</th>
<th class="noWrap">R2</th>
<th class="noWrap">R3</th>
</tr>
</thead>
<tbody>
</table>
LI 点击生成的代码?
谢谢 哈康
【问题讨论】:
标签: javascript c# html automation screen-scraping