How to parse this web page (and convert into a dictionary) in Python
Question: I want to fetch some data from a certain web page (online book store).

The web pages look like this: <http://www.rob389.com/dp/tr/11/9789754681383>

I want to parse the `<script>` section that contains the following string:

    
    
    tOBJ.DATA[0].MMM00_ITEM_CODE="9789754681383"
    

Where _9789754681383_ is the ISBN number.

I first need to find and extract the correct `<script>` section.

Then, I want to iterate through the content of the **tOBJ.DATA[0]** object and
convert it into a dictionary which would look like:

    
    
    my_dict["MMM00_ITEM_CODE"] = "9789754681383"
    my_dict["MMM00_TITLE"] = "Uykusuz Bir Gece"
    

And so on...

I guess it's possible to do it with python with few number of lines, but I
cannot figure out.

Any suggestions?

Thanks in advance.

PS: Any other parsing suggestions are welcome.


Answer: You can do it with
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) and a little
bit of code:

    
    
    from bs4 import BeautifulSoup
    import urllib2
    from urlparse import urlsplit
    
    def isbnExtractor(url):
    
        urlContent = url.strip('/').split('/')
        print urlContent[6]
    

And this should do the trick. Like this:

    
    
    PS python
    Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from parse import isbnExtractor
    >>> url = "http://www.rob389.com/dp/tr/11/9789754681383"
    >>> isbnExtractor(url)
    9789754681383
    

