I needed it when I was researching, so it's just a memo I mainly referred to the following http://qiita.com/code_monkey/items/0d38a92a2a2026f5ec82 http://qiita.com/Kodaira_/items/eb5cdef4c4e299794be3
Please insert the Google package in advance with pip install google
etc.
search.py
import linecache
from google import search
def google_search(query, limit=1):
for url in search(query, lang="jp", num=limit, stop=1):
print url
def main():
num_lines = sum(1 for line in open('hoge.txt'))
target_line = linecache.getline('hoge.txt', num_lines)
print(target_line)
linecache.clearcache()
google_search(target_line)
if __name__ == '__main__':
main()
The file looks like this
hoge.txt
hello python
ok google
hey siri
hey siri
https://dekiru.net/article/5312/
Apple's official page doesn't come to the top ... orz
I used the code from other articles as it is and made it with a secret sauce. I think that it is a lot of ugly code because it is a code that a person who originally escaped from programming made in a hurry