I got to a fun part of the book today where I followed Al Sweigart’s instructions to create a program that would have the computer automatically open the browser with all the top search results on any search topics in new tabs.
So here’s the script – lucky.py:
It was pretty straightforward but when I ran it on Terminal, I encountered errors when I did not give the .py file permission to execute and did not know how to go about searching for the topics on the command line. I Googled for ages but couldn’t seem to find any screenshots that would show me the correct way to do it. All I could find were texts and more texts. Useful but really not useful.
Well, it could be for people with some level of experience with programming but not for me.
(So I asked my boyfriend.)
This is a screenshot of how I changed the lucky.py file’s permissions to make it executable:
I made sure my file was in the current working directory (learning from past mistakes) then ran chmod +x lucky.py.
Once lucky.py was executable, I typed in python3 lucky.py coldplay:
And TA-DA! My browser pops up the following:
So useful!
BeautifulSoup is one of my favourite module when I scrape the web. I think that although BeautifulSoup needs less syntax but urllib is also pretty cool as it has features like adding the domain name to the relative link, I learned new stuff from you post (Maybe you should try urllib out if you haven’t already) . Do you like Cold play’s music ? I like like their collaboration with the “chain smokers “. Chris Martin’s voice is just divine.
Have a nice day:)
LikeLiked by 1 person
I’ll check it out! Yes, Coldplay’s one of my favourite bands of all time. They are great live!
LikeLiked by 1 person