Get sourcecode for urls
Question: I have following codes:

    
    
    import urllib2
    from itertools import product
    
    with open('urllist.txt') as urllist:
        urls=[line.strip() for line in urllist]
    
    for url in product(urls):
        usock = urllib2.urlopen(url)
        data = usock.read()
        usock.close()
        sourcecode=open('./sourcecode', 'w+')
        sourcecode.write(data)
    

When I ran it, it gave:

    
    
    Traceback (most recent call last):
      File "12.py", line 8, in <module>
        usock = urllib2.urlopen(url)
      File "/opt/python2.7.1/lib/python2.7/urllib2.py", line 126, in urlopen
        return _opener.open(url, data, timeout)
      File "/opt/python2.7.1/lib/python2.7/urllib2.py", line 383, in open
        req.timeout = timeout
    AttributeError: 'tuple' object has no attribute 'timeout'
    

Any idea how to fix it? Many thanks!


Answer: [`itertools.product`](http://docs.python.org/2/library/itertools.html#itertools.product)
returns a tuple not the item itself.:

    
    
    >>> from itertools import product
    >>> lis = ['a','b','c']
    >>> for p in product(lis):
    ...     print p
    ...     
    ('a',)
    ('b',)
    ('c',)
    

Use a simple loop over urls:

    
    
    for url in urls:
        usock = urllib2.urlopen(url)
    

