English 中文(简体)
我怎样才能在下午下载这一网页?
原标题:How come I can t download this webpage in python?

www.un.或g/Depts/DGACM/index_spanish.htm 请尝试:

curl http://www.windowsphone.com/en-US/apps?list=free

结果是:

    <html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://login.live.com/login.srf?wa=wsignin1.0&amp;rpsnv=11&amp;checkda=1&amp;ct=1320735308&amp;rver=6.1.6195.0&amp;wp=MBI&amp;wreply=http:%2F%2Fwww.windowsphone.com%2Fen-US%2Fapps%3Flist%3Dfree&amp;lc=1033&amp;id=268289">here</a>.</h2>
</body></html>

def download(source_url):
    try:
        socket.setdefaulttimeout(10)        
        agents = [ Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) , Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1) , Microsoft Internet Expl或er/4.0b1 (Windows 95) , Opera/8.00 (Windows NT 5.1; U; en) ]
        ree = urllib2.Request(source_url)
        ree.add_header( User-Agent ,random.choice(agents))
        resp = urllib2.urlopen(ree)
        htmlSource = resp.read()
        return htmlSource
    except Exception, e:
        print e
        return ""

download( http://www.windowsphone.com/en-US/apps?list=free )

结果是:

<html><head><meta http-equiv="REFRESH" content="0; URL=http://www.windowsphone.com/en-US/apps?list=free"><script type="text/javascript">function OnBack(){}</script></head></html>

我想下载网页的实际来源。

最佳回答
问题回答

弗莱茨克确实对此(+1)。

另一个直截了当的方法是Netcat,这基本上是一个强大的电话网络。

因此,请你说,你想对你在吉大港定居地的申请中的内容进行反驳:

$ nc www.windowsphone.com 80
GET /en-US/apps?list=free HTTP/1.0
Host: www.windowsphone.com
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

这将向服务器发送申请头盔(需要报到进入钥匙twice发送)。

之后,服务器将作出反应:

HTTP/1.1 302 Found
Location: https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&checkda=1&ct=1320745265&rver=6.1.6195.0&wp=MBI&wreply=http:%2F%2Fwww.windowsphone.com%2Fen-US%2Fapps%3Flist%3Dfree&lc=1033&id=268289
Server: Microsoft-IIS/7.5
Set-Cookie: WPMSLSS=SLSS=1; domain=www.windowsphone.com; path=/; HttpOnly
X-Powered-By: ASP.NET
X-Server: SN2CONXWWBA06
Date: Tue, 08 Nov 2011 09:41:05 GMT
Connection: close
Content-Length: 337

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://login.live.com/login.srf?wa=wsignin1.0&amp;rpsnv=11&amp;checkda=1&amp;ct=1320745265&amp;rver=6.1.6195.0&amp;wp=MBI&amp;wreply=http:%2F%2Fwww.windowsphone.com%2Fen-US%2Fapps%3Flist%3Dfree&amp;lc=1033&amp;id=268289">here</a>.</h2>
</body></html>

因此,服务器退回了302台,即《吉大港山区地位法》转头,从而促使“浏览器”打开在地头上的URL。

Netcat is a great tool to debug and trace all kinds of network communication and helped me a lot when I wanted to dig a little deeper into the HTTP protocol.





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签