Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.045 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'urllib2': 0.07; 'python': 0.08; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; 'subject:login': 0.16; 'cc:addr :python-list': 0.16; 'possibly': 0.16; 'url:blog': 0.16; 'cheers,': 0.18; "aren't": 0.21; 'cc:2**0': 0.22; 'header:In- Reply-To:1': 0.22; 'required.': 0.28; 'right.': 0.28; 'import': 0.28; 'message-id:@mail.gmail.com': 0.29; 'fix': 0.29; 'cc:addr:python.org': 0.30; 'html.': 0.30; "skip:' 10": 0.30; 'specified': 0.31; 'chris': 0.32; 'values': 0.32; 'probably': 0.33; "can't": 0.33; 'there': 0.33; 'rather': 0.35; 'received:209.85.160': 0.35; 'response': 0.37; 'page': 0.37; 'could': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'itself.': 0.39; 'subject:with': 0.39; 'appreciated.': 0.39; 'data': 0.39; 'case': 0.39; 'called': 0.40; 'login': 0.69; 'url:login': 0.77; 'sender:addr:chris': 0.84; 'url:hi': 0.84; 'url:rebertia': 0.84; 'to:none': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=glF1F1LYGLV36En9qjPhePOce5CEqk6EDbtIVybEVQw=; b=OBzb7D2Tv64mfGNFhdZ1XHQsPJzl4mvmykrXrG+RnVcNUgAB6C5au/M5NPUNmtpD7h 12aVvooiE5hBRBYrGMkUCbMqc6Bs3ODy/+6g05IDsiAC6HI2rhCl3zv0YSCoZ/PtOjnS sOErA52TtjoRKMVa1a64HPQBhXYnajMi5IxWM= MIME-Version: 1.0 Sender: chris@rebertia.com In-Reply-To: References: Date: Sun, 14 Aug 2011 08:07:37 -0700 X-Google-Sender-Auth: oJCr7GkYlY3IkIFQ-UtrhMzxDNo Subject: Re: login with urllib2 From: Chris Rebert Cc: python-list Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1313334460 news.xs4all.nl 23850 [2001:888:2000:d::a6]:35647 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11395 2011/8/14 =E5=AE=88=E6=A0=AA=E5=BE=85=E5=85=94 <1248283536@qq.com>: > please to see my code: > import urllib > import urllib2 > > url =3D 'http://hi.baidu.com/' > values =3D {'username' : '******','password' : '******' } > > data =3D urllib.urlencode(values) > req =3D urllib2.Request(url,data) > response =3D urllib2.urlopen(req) > the_page =3D response.read() > > i can't to login ,why?username and password=C2=A0 are=C2=A0 right. > any word=C2=A0 appreciated. Use the URL specified as the
's action, which in this case is https://passport.baidu.com/?login , rather than the URL of the login page itself. The fields aren't called "username" and "password"; read the page's HTML. You'll also see that there are a few hidden form fields that are probably required. Finally, even if you fix these problems, the site could possibly block Python based on its User-agent header. Cheers, Chris -- http://blog.rebertia.com