0

As of now I have created a basic program in python 2.7 using urllib2 and re that gathers the html code of a website and prints it out for you as well as indexing a keyword. I would like to create a much more complex and dynamic program which could gather data from websites such as sports or stock statistics and aggregate them into lists which could then be used in analysis in something such as an excel document etc. I'm not asking for someone to literally write the code. I simply need help understanding more of how I should approach the code: whether I require extra libraries, etc. Here is the current code. It is very simplistic as of now.:

    import urllib2
    import re 

    y = 0

    while(y == 0):
        x = str(raw_input("[[[Enter URL]]]"))
        keyword = str(raw_input("[[[Enter Keyword]]]"))
        wait = 0
        try:
            req = urllib2.Request(x)
            response = urllib2.urlopen(req)
            page_content = response.read()
            idall = [m.start() for m in re.finditer(keyword,page_content)]
            wait = raw_input("")
            print(idall)
            wait = raw_input("")
            print(page_content)

        except urllib2.HTTPError as e:
            print e.reason
Orren Ravid
  • 560
  • 1
  • 6
  • 24

1 Answers1

4

You can use requests to deal with interaction with website. Here is link for it. http://docs.python-requests.org/en/latest/

And then you can use beautifulsoup to handle the html content. Here is link for it.http://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html

They're more ease of use than urllib2 and re. Hope it helps.

Stephen Lin
  • 4,852
  • 1
  • 13
  • 26