Skip to content Skip to sidebar Skip to footer

Python Script That Runs An Iterating Google Search And Prints Top Results And Links

I want to write a python script that will pull the title and url of the top three links of successive google searches. For example, I want to be able to google '3 mile run', '4 mil

Solution 1:

Indent errors are only caused by indentation problems.

It seems obvious, but check your code does not have, say a mixture of tabs and spaces for indenting. Your editor might show 4x spaces the same size as one tab. But python does not see it this way.

In the Vi (or Vim) editor, a command to replace the tabs with spaces would be:

:1,$s/[CTRL-v][TAB]/    /g

Failing that you can manually remove and replace them. With spaces or tabs, but I suggest spaces.

Copying and pasting your code, it works for me, so probably the act of putting it here has normalised the mix of spaces and tabs.

Solution 2:

Using ViM, you can fix it very easily:

:set et
:retab:w

It may help you:

  • :et (:expandtabs) tells ViM to prefer spaces over tabs;
  • :retab tells ViM to rebuild all tabs as its preferences (spaces);
  • finally, :w saves your file changes.

If the tabs expand to odd count of spaces, undo the retab, and try:

:set tabstop=4

Then :retab and :w.

You can tell ViM always to deal with Python files this way. Edit ~/.vim/ftdetect/python.vim (if it doesn’t exists, create it):

au BufNewFile,BufRead *.py  set filetype=python
au BufNewFile,BufRead *.pyw set filetype=python
au FileType python set et
au FileType python set tabstop=4

Post a Comment for "Python Script That Runs An Iterating Google Search And Prints Top Results And Links"