Oh, BeautifulSoup.

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:

Screen Shot 2017-08-01 at 4.31.12 PM

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:

Screen Shot 2017-08-01 at 4.43.47 PM

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:

Screen Shot 2017-08-01 at 5.11.37 PM

And TA-DA! My browser pops up the following:

Screen Shot 2017-08-01 at 5.13.59 PM.png

So useful!

2 thoughts on “Oh, BeautifulSoup.

  1. 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:)

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s