AutoHotkey Community

It is currently May 27th, 2012, 2:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: February 3rd, 2010, 2:57 am 
Offline

Joined: August 3rd, 2009, 7:02 am
Posts: 42
As I data mine Google, I am wondering how to replace no results, with the number 0.

i.e. if there are no hits for say, John Biblotit on google books, there would be a zero, instead of that entry being blank.

how do you use RegExReplace to replace no result?

Thanks in advance!

Here is my existing code:

Code:
S := 1
L0 := 0

URLDownloadToFile, http://en.wikipedia.org/wiki/Category:Chinese_centenarians, wiki.txt
; shorter list Category:Chinese_centenarians
FileRead, Con, wiki.txt
While (Pos := RegExMatch(Con, "<li><a href=""/wiki/.*?"" title=""(\S.+?)"">", Sub, S)) { 
; original script: <ul><li><a href="/wiki/Hiroshi_Takeyasu" title="Hiroshi Takeyasu">Hiroshi Takeyasu</a></li></ul>
        L0++
NewStr := RegExReplace(Q, "\(.*?\)", "", count) ; removes the parenethis in a name.
; msgbox %NewStr% for testing
        Q := Sub1
        S := Pos + StrLen(Sub1) + 13


        URLDownloadToFile, http://news.google.com/archivesearch?q="%NewStr%"+&btnG=Search+Archives, google.txt
        FileRead, CCon, google.txt
        RegExMatch(CCon, "of (?:about )?<b>(\S+)</b>", Sub)
        L%A_Index%Results := RegExReplace(Sub1, "[^\d]")

;msgbox, %Q% "http://books.google.com/books?q=+"%NewStr%"+&btnG=Search+Books" ; for testing
        URLDownloadToFile, http://books.google.com/books?q=+"%Q%"+&btnG=Search+Books, google.htm
        FileRead, CCon1, google.htm
        RegExMatch(CCon1, "of (?:about )?<b>(\S+)</b>", Subl)
        n%A_Index%Results := RegExReplace(Subl1, "[^\d]")

;msgbox, %Q% "http://scholar.google.com/scholar?&q="%NewStr%"""" ; for testing
       URLDownloadToFile, http://scholar.google.com/scholar?&q="%Q%, google.htm
        FileRead, CCon1, google.htm
        RegExMatch(CCon1, "of (?:about )?<b>(\S+)</b>", Subl)
        m%A_Index%Results := RegExReplace(Subl1, "[^\d]")
       
      L%A_Index% := NewStr
}

L := "<span class=""plainlinks"">`r`n{|class=""wikitable sortable""`r`n!Name!!Google books!!Google news!!Google scholar"
;L := "Found " . L0 . " results.`r`n"
Loop %L0%
L .= "`r`n|-valign=top `r`n|align=left|[[" . L%A_Index%                               

         . "]]`n|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:""" . L%A_Index% .

"""}}+&btnG=Search+Archives "  . L%A_Index%Results .                                

"]`n|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"""  . L%A_Index% . """}}+&btnG=Search+Books " . n%

A_Index%Results                                  . "]`n|align=center|<!-

-scholar--> [http://scholar.google.com/scholar?&q={{urlencode:""" . L%A_Index% . """}} " . m%A_Index%Results . "]"
;MsgBox %L% ; for testing
FileAppend, %L%, %a_scriptdir%\L.txt
Run, %a_scriptdir%\L.txt
Return


Last edited by rum on February 3rd, 2010, 9:24 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 3:56 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Maybe you could do something like this:
Code:
If ( Variable = "" )
  Variable := "0" ; quotation marks not really necessary

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 8:02 am 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3330
Location: Simi Valley, CA
Code:
RegexReplace( RegExReplace(Subl1, "[^\d]"), "^$", "0" )

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2010, 9:32 am 
Offline

Joined: August 3rd, 2009, 7:02 am
Posts: 42
[VxE] wrote:
Code:
RegexReplace( RegExReplace(Subl1, "[^\d]"), "^$", "0" )


It gave me some strange results, none of the actual numbers given are accurate, in addition there is an extra line at the beginning that wasnt there before.....

Results:

Code:
<span class="plainlinks">
{|class="wikitable sortable"
!Name!!Google books!!Google news!!Google scholar
|-valign=top
|align=left|[[]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:""}}+&btnG=Search+Archives 0]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:""}}+&btnG=Search+Books 840]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:""}} 1550]
|-valign=top
|align=left|[[Ba Jin]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Ba Jin"}}+&btnG=Search+Archives 1550]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Ba Jin"}}+&btnG=Search+Books 232]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Ba Jin"}} 25]
|-valign=top
|align=left|[[Bei Shizhang]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Bei Shizhang"}}+&btnG=Search+Archives 25]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Bei Shizhang"}}+&btnG=Search+Books 0]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Bei Shizhang"}} 288]
|-valign=top
|align=left|[[Chang Ch'ün]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Chang Ch'ün"}}+&btnG=Search+Archives 288]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Chang Ch'ün"}}+&btnG=Search+Books 643]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Chang Ch'ün"}} 381]
|-valign=top
|align=left|[[Chen Tuan]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Chen Tuan"}}+&btnG=Search+Archives 381]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Chen Tuan"}}+&btnG=Search+Books 30]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Chen Tuan"}} 10]
|-valign=top
|align=left|[[Dazu Huike]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Dazu Huike"}}+&btnG=Search+Archives 10]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Dazu Huike"}}+&btnG=Search+Books 262]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Dazu Huike"}} 57]
|-valign=top
|align=left|[[Jiang Ziya]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Jiang Ziya"}}+&btnG=Search+Archives 57]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Jiang Ziya"}}+&btnG=Search+Books 1]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Jiang Ziya"}} 18]
|-valign=top
|align=left|[[Li Cairong]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Li Cairong"}}+&btnG=Search+Archives 18]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Li Cairong"}}+&btnG=Search+Books 0]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Li Cairong"}} 39]
|-valign=top
|align=left|[[Lü Zhengcao]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Lü Zhengcao"}}+&btnG=Search+Archives 39]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Lü Zhengcao"}}+&btnG=Search+Books 709]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Lü Zhengcao"}} 2390]
|-valign=top
|align=left|[[Run Run Shaw]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Run Run Shaw"}}+&btnG=Search+Archives 2390]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Run Run Shaw"}}+&btnG=Search+Books 416]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Run Run Shaw"}} 31]
|-valign=top
|align=left|[[Soong May-ling]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Soong May-ling"}}+&btnG=Search+Archives 31]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Soong May-ling"}}+&btnG=Search+Books 529]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Soong May-ling"}} 73]
|-valign=top
|align=left|[[Su Buqing]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Su Buqing"}}+&btnG=Search+Archives 73]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Su Buqing"}}+&btnG=Search+Books 595]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Su Buqing"}} 510]
|-valign=top
|align=left|[[Sun Simiao]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Sun Simiao"}}+&btnG=Search+Archives 510]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Sun Simiao"}}+&btnG=Search+Books 94]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Sun Simiao"}} 11]
|-valign=top
|align=left|[[Wu Yee-sun]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Wu Yee-sun"}}+&btnG=Search+Archives 11]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Wu Yee-sun"}}+&btnG=Search+Books 697]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Wu Yee-sun"}} 3980]
|-valign=top
|align=left|[[Xiao Ke]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Xiao Ke"}}+&btnG=Search+Archives 3980]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Xiao Ke"}}+&btnG=Search+Books 764]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Xiao Ke"}} 487]
|-valign=top
|align=left|[[Xue Muqiao]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Xue Muqiao"}}+&btnG=Search+Archives 487]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Xue Muqiao"}}+&btnG=Search+Books 1142]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Xue Muqiao"}} 590]
|-valign=top
|align=left|[[Xue Yue]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Xue Yue"}}+&btnG=Search+Archives 590]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Xue Yue"}}+&btnG=Search+Books 407]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Xue Yue"}} 107]
|-valign=top
|align=left|[[Zhou Youguang]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Zhou Youguang"}}+&btnG=Search+Archives 107]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Zhou Youguang"}}+&btnG=Search+Books 664]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Zhou Youguang"}} 586]
|-valign=top
|align=left|[[Katherine Young]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Katherine Young"}}+&btnG=Search+Archives 586]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Katherine Young"}}+&btnG=Search+Books 29]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Katherine Young"}} 23]
|-valign=top
|align=left|[[Sun Yuanliang]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Sun Yuanliang"}}+&btnG=Search+Archives 23]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Sun Yuanliang"}}+&btnG=Search+Books 638]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Sun Yuanliang"}} 226]
|-valign=top
|align=left|[[Zhang Daoling]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Zhang Daoling"}}+&btnG=Search+Archives 226]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Zhang Daoling"}}+&btnG=Search+Books 730]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Zhang Daoling"}} 784]
|-valign=top
|align=left|[[Zhang Xueliang]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Zhang Xueliang"}}+&btnG=Search+Archives 784]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Zhang Xueliang"}}+&btnG=Search+Books 115]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Zhang Xueliang"}} 30]
|-valign=top
|align=left|[[Zhaozhou Congshen]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Zhaozhou Congshen"}}+&btnG=Search+Archives 30]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Zhaozhou Congshen"}}+&btnG=Search+Books 909]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Zhaozhou Congshen"}} 0]
|-valign=top
|align=left|[[Zheng Ji ]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Zheng Ji "}}+&btnG=Search+Archives 0]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Zheng Ji "}}+&btnG=Search+Books 20]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Zheng Ji "}} 0]
|-valign=top
|align=left|[[Joseph Meng Ziwen]]
|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:"Joseph Meng Ziwen"}}+&btnG=Search+Archives 0]
|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"Joseph Meng Ziwen"}}+&btnG=Search+Books 370]
|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:"Joseph Meng Ziwen"}} 74]


MasterFocus wrote:
Maybe you could do something like this:
Code:
If ( Variable = "" )
  Variable := "0" ; quotation marks not really necessary


I tried

Quote:
If ( L = "" )
L := 0 ; quotation marks not really necessary


didn't work, probably doing it wrong, thanks though!


Last edited by rum on February 3rd, 2010, 9:45 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 9:36 am 
Check out URLDownloadToVar too!

Code:
MyVar := ""
Status := MyVar = "" ? 0:MyVar
MsgBox % Status


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2010, 11:05 am 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Code:
; ...
NewStr := RegExReplace(Sub1, "\(.*?\)", "", count) ; removes the parenethis in a name.
; ...
L%A_Index%Results := RegexReplace(RegExReplace(Sub1, "\D"), "^$", "0")
; ...
n%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")
; ...
m%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")
; ...

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: February 3rd, 2010, 7:09 pm 
Offline

Joined: August 3rd, 2009, 7:02 am
Posts: 42
nick wrote:
Code:
; ...
NewStr := RegExReplace(Sub1, "\(.*?\)", "", count) ; removes the parenethis in a name.
; ...
L%A_Index%Results := RegexReplace(RegExReplace(Sub1, "\D"), "^$", "0")
; ...
n%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")
; ...
m%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")
; ...


Ha it worked! Good to see you again Nick! Thank you everyone for your suggestions!

Code:
f8::
S := 1
L0 := 0

URLDownloadToFile,http://en.wikipedia.org/w/index.php?title=Category:Unreferenced_BLPs_from_April_2007&from=Li+Na, wiki.txt
; shorter list Category:Chinese_centenarians
FileRead, Con, wiki.txt
While (Pos := RegExMatch(Con, "<li><a href=""/wiki/.*?"" title=""(\S.+?)"">", Sub, S)) { 
; original script: <ul><li><a href="/wiki/Hiroshi_Takeyasu" title="Hiroshi Takeyasu">Hiroshi Takeyasu</a></li></ul>
        L0++
        Q := Sub1
        S := Pos + StrLen(Sub1) + 13
NewStr := RegExReplace(Q, "\(.*?\)", " ", count) ; removes the parenthesis in a name.
; msgbox %NewStr% for testing

        URLDownloadToFile, http://news.google.com/archivesearch?q="%NewStr%"+&btnG=Search+Archives, google.txt
        FileRead, CCon, google.txt
        RegExMatch(CCon, "of (?:about )?<b>(\S+)</b>", Sub)
        L%A_Index%Results := RegexReplace(RegExReplace(Sub1, "\D"), "^$", "0")

;msgbox, %Q% "http://books.google.com/books?q=+"%NewStr%"+&btnG=Search+Books" ; for testing
        URLDownloadToFile, http://books.google.com/books?q=+"%Q%"+&btnG=Search+Books, google.htm
        FileRead, CCon1, google.htm
        RegExMatch(CCon1, "of (?:about )?<b>(\S+)</b>", Subl)
        n%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")

;msgbox, %Q% "http://scholar.google.com/scholar?&q="%NewStr%"""" ; for testing
       URLDownloadToFile, http://scholar.google.com/scholar?&q="%Q%, google.htm
        FileRead, CCon1, google.htm
        RegExMatch(CCon1, "of (?:about )?<b>(\S+)</b>", Subl)
        m%A_Index%Results := RegexReplace(RegExReplace(Subl1, "\D"), "^$", "0")
       
      L%A_Index% := NewStr
}

L := "<span class=""plainlinks"">`r`n{|class=""wikitable sortable""`r`n!Name!!Google news!!Google books!!Google scholar"
;L := "Found " . L0 . " results.`r`n"
Loop %L0%
L .= "`r`n|-valign=top `r`n|align=left|[[" . L%A_Index% . "]]`n|align=center|<!--news-->[http://news.google.com/archivesearch?q={{urlencode:""" . L%A_Index% . """}}+&btnG=Search+Archives "  . L%A_Index%Results .  "]`n|align=center|<!--books-->[http://books.google.com/books?q=+{{urlencode:"""  . L%A_Index% . """}}+&btnG=Search+Books " . n%A_Index%Results  . "]`n|align=center|<!--scholar--> [http://scholar.google.com/scholar?&q={{urlencode:""" . L%A_Index% . """}} " . m%A_Index%Results . "]"
;MsgBox %L% ; for testing
FileAppend, %L%, %a_scriptdir%\L.txt
Run, %a_scriptdir%\L.txt
Return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: nimda, poserpro, rbrtryn, sjc1000, Yahoo [Bot] and 16 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group