<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%3A_search-google.py</id>
	<title>Python: search-google.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://onnocenter.or.id/wiki/index.php?action=history&amp;feed=atom&amp;title=Python%3A_search-google.py"/>
	<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Python:_search-google.py&amp;action=history"/>
	<updated>2026-06-10T09:01:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.4</generator>
	<entry>
		<id>https://onnocenter.or.id/wiki/index.php?title=Python:_search-google.py&amp;diff=46925&amp;oldid=prev</id>
		<title>Onnowpurbo at 22:21, 5 February 2017</title>
		<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Python:_search-google.py&amp;diff=46925&amp;oldid=prev"/>
		<updated>2017-02-05T22:21:33Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left diff-editfont-monospace&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 22:21, 5 February 2017&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l36&quot; &gt;Line 36:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 36:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;   &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  def scrape_results(br):&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  def scrape_results(br):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;     # Xpath will find a subnode of h3, a[@href] specifies that we only want &amp;lt;a&amp;gt; nodes with&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;     # any href attribute that are subnodes of &amp;lt;h3&amp;gt; tags that have a class of 'r'&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      links = br.find_elements_by_xpath(&amp;quot;//h3[@class='r']/a[@href]&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      links = br.find_elements_by_xpath(&amp;quot;//h3[@class='r']/a[@href]&amp;quot;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      results = []&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;      results = []&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
	<entry>
		<id>https://onnocenter.or.id/wiki/index.php?title=Python:_search-google.py&amp;diff=46807&amp;oldid=prev</id>
		<title>Onnowpurbo: Created page with &quot; #!/usr/bin/env python2  # -*- coding: utf8 -*-    import sys  import time  import random  import argparse    from selenium import webdriver  from selenium.webdriver.support.u...&quot;</title>
		<link rel="alternate" type="text/html" href="https://onnocenter.or.id/wiki/index.php?title=Python:_search-google.py&amp;diff=46807&amp;oldid=prev"/>
		<updated>2017-01-29T23:24:00Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; #!/usr/bin/env python2  # -*- coding: utf8 -*-    import sys  import time  import random  import argparse    from selenium import webdriver  from selenium.webdriver.support.u...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt; #!/usr/bin/env python2&lt;br /&gt;
 # -*- coding: utf8 -*-&lt;br /&gt;
 &lt;br /&gt;
 import sys&lt;br /&gt;
 import time&lt;br /&gt;
 import random&lt;br /&gt;
 import argparse&lt;br /&gt;
 &lt;br /&gt;
 from selenium import webdriver&lt;br /&gt;
 from selenium.webdriver.support.ui import Select, WebDriverWait&lt;br /&gt;
 from selenium.common.exceptions import NoSuchFrameException&lt;br /&gt;
 from selenium.webdriver.common.keys import Keys&lt;br /&gt;
 &lt;br /&gt;
 # If this script no longer fetches any results check the XPath&lt;br /&gt;
 &lt;br /&gt;
 def parse_args():&lt;br /&gt;
     parser = argparse.ArgumentParser()&lt;br /&gt;
     parser.add_argument('-s', '--search', help='Enter the search term')&lt;br /&gt;
     parser.add_argument('-p', '--pages', default='1', help='Enter how many pages to scrape (1 page = 100 results)')&lt;br /&gt;
     return parser.parse_args()&lt;br /&gt;
 &lt;br /&gt;
 def start_browser():&lt;br /&gt;
     br = webdriver.Firefox()&lt;br /&gt;
     br.implicitly_wait(10)&lt;br /&gt;
     return br&lt;br /&gt;
 &lt;br /&gt;
 def get_ua():&lt;br /&gt;
     ua_list = ['Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36',&lt;br /&gt;
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36',&lt;br /&gt;
                'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14',&lt;br /&gt;
                'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0',&lt;br /&gt;
                'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36',&lt;br /&gt;
                'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0']&lt;br /&gt;
     ua = random.choice(ua_list)&lt;br /&gt;
     return ua&lt;br /&gt;
 &lt;br /&gt;
 def scrape_results(br):&lt;br /&gt;
     # Xpath will find a subnode of h3, a[@href] specifies that we only want &amp;lt;a&amp;gt; nodes with&lt;br /&gt;
     # any href attribute that are subnodes of &amp;lt;h3&amp;gt; tags that have a class of 'r'&lt;br /&gt;
     links = br.find_elements_by_xpath(&amp;quot;//h3[@class='r']/a[@href]&amp;quot;)&lt;br /&gt;
     results = []&lt;br /&gt;
     for link in links:&lt;br /&gt;
         title = link.text.encode('utf8')&lt;br /&gt;
         url = link.get_attribute('href')&lt;br /&gt;
         title_url = (title, url)&lt;br /&gt;
         results.append(title_url)&lt;br /&gt;
     return results &lt;br /&gt;
 &lt;br /&gt;
 def go_to_page(br, page_num, search_term):&lt;br /&gt;
     page_num = page_num - 1&lt;br /&gt;
     start_results = page_num * 100&lt;br /&gt;
     start_results = str(start_results)&lt;br /&gt;
     url = 'https://www.google.com/webhp?#num=100&amp;amp;start='+start_results+'&amp;amp;q='+search_term&lt;br /&gt;
     print '[*] Fetching 100 results from page '+str(page_num+1)+' at '+url&lt;br /&gt;
     br.get(url)&lt;br /&gt;
     time.sleep(2) &lt;br /&gt;
 &lt;br /&gt;
 def main():&lt;br /&gt;
     args = parse_args()&lt;br /&gt;
     br = start_browser()&lt;br /&gt;
     if not args.search:&lt;br /&gt;
         sys.exit(&amp;quot;[!] Enter a term or phrase to search with the -s option: -s 'dan mcinerney'&amp;quot;)&lt;br /&gt;
     search_term = args.search&lt;br /&gt;
     pages = args.pages &lt;br /&gt;
 &lt;br /&gt;
     all_results = []&lt;br /&gt;
     for page_num in xrange(int(pages)):&lt;br /&gt;
         page_num = page_num+1 # since it starts at 0&lt;br /&gt;
         go_to_page(br, page_num, search_term)&lt;br /&gt;
         titles_urls = scrape_results(br)&lt;br /&gt;
         for title in titles_urls:&lt;br /&gt;
             all_results.append(title) &lt;br /&gt;
 &lt;br /&gt;
     for result in all_results:&lt;br /&gt;
         title = result[0]&lt;br /&gt;
         url = result[1]&lt;br /&gt;
         print '[+]', title, '--', url &lt;br /&gt;
 &lt;br /&gt;
 main()&lt;/div&gt;</summary>
		<author><name>Onnowpurbo</name></author>
	</entry>
</feed>