Skip to main content

Posts

Showing posts from May, 2018

A simple Python program for parsing Amazon to display requried product list with price

You need two packages in Python : 'lxml' and 'requests' in order to perform the parsing. Actually, we use a template url of Amazon in order to find the content that we require. We attach the template url with the keyword that is inputted from the user (in this case, 'headsets' is being used as the default string to search). After that, there comes the role of XPath for parsing the web-content according to the html tags being used over there. You can learn a lot by seeing this simple example:   Output: However, you might be agitated because this code though is correct, might produce null output because of Response = 503 which tells that there is no connection with your computer and the website server that you want to withdraw the data. In order to smoothly run, you may need to modify the code as:
It gives a particular root of the predefined polynomial equation. The root lies in the upper and lower bound prescribed by the user. The output appears as:

A Python program that counts the number of given word in a file.

This Python 2.7 program accepts a word (string) from user and counts the occurrence of that word in the file chosen by user. In this program, the words with a punctuation either at the beginning or at the end (like: But, ) is also considered if that word matches with the inputted word. Suppose, if the given word is 'it' and the file is 'alice_short.txt' then the output looks like: alice_short.txt :

Recursive function in Python for evaluating Taylor's Series for Exponential Function

This Python 2.7 program, takes two inputs, x and n from a user and then evaluates the numerical value of Taylor's series for the exponential function. In the program, x indicates the power of e and n represents the number of terms to be included from the Taylor's series expansion. Furthermore, the program also prints the absolute value of the percentage error in the Taylor's approximation. The output and input of the program appears as: