2011-12-12 71 views
0

給出一串字符串,我想從每個字符串的網站(例如sciencedirect.com)中查找搜索結果的數量。現有的答案Number of Google Results from Excel適用於Google。來自Excel的搜索結果數量

不幸的是這種解決方案創建一個從字符串即谷歌搜索例如搜索URL中包含單詞例子。我想使用的網站不這樣做。

一種例如搜索返回URL http://www.sciencedirect.com/science?_ob=ArticleListURL&_method=list&_ArticleListID=1860967815&_sort=r&_st=13&view=c&_acct=C000053194&_version=1&_urlVersion=0&_userid=1495569&md5=0ef30742e917da15236ef1824058a1db&searchtype=a

任何想法,我怎麼achived相同的結果與這種類型的搜索引擎。

+0

難道你不能從API獲取這些信息而不是抓取? HTTP:// WWW。developer.sciverse.com/ – JimmyPena

回答

0

當您點擊搜索按鈕時,您必須檢查您提交的表單。表單發送一個包含搜索條件的GET請求,但隨後您將被重定向到結果列表頁面,並且結果頁面的URL不再包含搜索條件。

我已經成功地搜索「文集」這個URL:

http://www.sciencedirect.com/science?_ob=QuickSearchURL&_method=submitForm&_acct=C000228598&_origin=home&_zone=qSearch&md5=61ce8901b141d527683913a240486ac4&qs_all=corpus 

需要注意的是你必須做的就是

  1. 下載起始頁http://www.sciencedirect.com/
  2. 提取隱藏字段從搜索表單
  3. 從隱藏字段中彙編搜索URL
  4. 搜索字詞與搜索URL
  5. 發送GET請求添加到搜索URL中qs_all領域
  6. 後續重定向

除了qs_all在這個網址的所有其他領域來自於形式爲隱藏領域。 這是相應形式的來源,因爲我下載了它(發送「文集」的搜索請求之前。):

<form name="qkSrch" method="get" target="_top" action="/science" style="margin:0px;"> 
<input type="hidden" name="_ob" value="QuickSearchURL"> 
<input type="hidden" name="_method" value="submitForm"> 
<input type="hidden" name="_acct" value="C000228598"> 
<input type="hidden" name="_origin" value="home"> 
<input type="hidden" name="_zone" value="qSearch"> 
<input type="hidden" name="md5" value="61ce8901b141d527683913a240486ac4"> 

<table border="0" width="100%" cellpadding="0" cellspacing="0" style="margin: 0;"> 
<tbody><tr valign="middle"> 

<!-- Code related for toggling labels --> 

    <td align="right"><label for="qs_all" id="fieldLabel">&nbsp;&nbsp;&nbsp;&nbsp;All fields</label></td> 
    <td align="left"><input class="textbox qsinput xpstyle" type="text" name="qs_all" id="qs_all" value="" size="30" maxlength="450" title="For example: heart attack AND behavior?" tabindex="1"></td> 



    <td align="right"><label for="qs_author">&nbsp;&nbsp;&nbsp;&nbsp;Author</label></td> 
    <td align="left" colspan="5"><input class="textbox qsinput xpstyle" type="text" name="qs_author" id="qs_author" value="" size="33" maxlength="450" title="e.g. J S Smith or John Smith or Smith JS" tabindex="2" style="_width:100%"></td> 
    <td nowrap="nowrap"> 

    </td><td></td><td></td> 
    <td align="right" nowrap="nowrap" width="90%" valign="middle"> 
    <a href="/science?_ob=MiamiSearchURL&amp;_method=requestForm&amp;_btn=Y&amp;_acct=C000228598&amp;_version=1&amp;_urlVersion=1&amp;_userid=10&amp;md5=18a1082f74248d90d465ee65804fd7db" style="vertical-align:bottom;font-size:0.92em;">Advanced search</a> 
    </td> 
</tr> 
<tr> 

    <td align="right"><label for="qs_title">&nbsp;&nbsp;&nbsp;&nbsp;Journal/Book&nbsp;title</label></td> 
    <td align="left"><input class="textbox qsinput xpstyle" type="text" id="qs_title" name="qs_title" value="" size="30" maxlength="450" title="For example: journal of molecular biology" tabindex="3"></td> 

    <td align="right" class="toggleQukSrch2"><label for="qs_vol" id="volField">&nbsp;&nbsp;&nbsp;&nbsp;Volume</label></td> 
    <td align="left" class="toggleQukSrch"><input class="textbox qsinput xpstyle" type="text" name="qs_vol" id="qs_vol" value="" size="3" maxlength="10" style="width:30px;" tabindex="4"></td> 
    <td align="right" class="toggleQukSrch2"><label for="qs_issue" id="issueField">&nbsp;&nbsp;Issue</label></td> 
    <td align="left" class="toggleQukSrch"><input class="textbox qsinput xpstyle" type="text" name="qs_issue" id="qs_issue" value="" size="3" maxlength="10" style="width:30px" tabindex="5"></td> 
    <td align="right" class="toggleQukSrch2"><label for="qs_pages" id="pageField">&nbsp;&nbsp;Page</label></td> 
    <td align="right" class="toggleQukSrch"><input class="textbox qsinput xpstyle" type="text" name="qs_pages" id="qs_pages" value="" size="3" maxlength="10" title="For example: 14-27" style="width:30px" tabindex="6"></td> 

    <td align="right" nowrap="nowrap"> 
    <input class="button" id="submit_search" type="Submit" alt="Submit Quick Search" title="Submit Quick Search" value="Search ScienceDirect" tabindex="8" name="sdSearch"> 
    </td> 



<td align="right" nowrap="nowrap" colspan="8" valign="bottom"> 
     <a class="icon_qmarkHelpsci_dir" href="/science?_ob=HelpURL&amp;_file=qs_tips.htm&amp;_acct=C000228598&amp;_version=1&amp;_urlVersion=0&amp;_userid=10&amp;md5=2bd779305b31602341744eaa786e2f0a" target="sdhelp" onmouseover="window.status='Help is Available';return true" onmouseout="window.status='';return true" onclick="var helpWin;helpWin=window.open('/science?_ob=HelpURL&amp;_file=qs_tips.htm&amp;_acct=C000228598&amp;_version=1&amp;_urlVersion=0&amp;_userid=10&amp;md5=2bd779305b31602341744eaa786e2f0a','sdhelp','scrollbars=yes,resizable=yes,directories=no,toolbar=no,menubar=no,status=no,width=760,height=570');helpWin.focus();return false" tabindex="9" style="font-size:0.92em;padding-right:0;">Search tips</a> 
    </td> 
    </tr> 
</tbody></table> 
</form> 

編輯 與如何從搜索結果頁中提取的結果數量持續。

你的假設是正確的,你將不得不改變代碼的其他部分,即提取結果數值。

讓我們繼續前面的例子。 當從「文集」搜索,你會發現在結果頁面的源代碼這一行:

<input type="hidden" name="TOTAL_PAGES" value="2836"> 

而且你要提取2836因此,你將尋找類似<input type="hidden" name="TOTAL_PAGES" value="並獲得subequent值在結束報價之前。

我不會告訴你如何在VBA中編寫代碼,但它是基本的字符串操作,所以我希望你能處理它。

+0

由於我無法將代碼適配到新網站,因此我不完全瞭解「Google的Excel結果數量」代碼正在執行的操作。我改變了search_url,但我假設代碼的其他部分需要更改 – falcs

+0

編輯答案,詳細闡述了這一個 – bpgergo

+0

當我查看結果頁面的源代碼時,我找不到你從哪裏以及如何提取? – falcs

相關問題