当我尝试使用阅读某些网页时,页面源如下所示:
<p/><table border="1" align="center" cellpadding="10"><tbody><tr><td><a href="/cgi-bin/query/C?c101:./temp/~c1011jI5AQ" title="Displays without navigation or highlighting">Printer Friendly</a>[<a href="/home/billdwnloadhelp.html">Help</a>]</td>
但是当我使用Python的urllib2,urllib或请求阅读此网页时,结果与以下内容相同:
<p/><a href="/[<a href="%s">Help</a>]</td>`/C?query:c101" Printer Friendly</a><p/>
那么,为什么我无法阅读所有信息并丢失了非常重要的部分C?c101:./temp/~c1011jI5AQ
???
答案 0 :(得分:0)
我不确定是否正确理解:第二个示例是您使用Python或Java获得的示例。而首先?是通过浏览器查看“源代码”获得的吗?在这种情况下,有三种可能的情况:
作为测试,您可以使用curl
下载页面并进行一些比较 - 它将非常适合该任务,因为在许多选项中,您有机会更改提供的用户代理标识到服务器 - 所以,假装是IE或Firefox或任何你喜欢的:
curl(1) Curl Manual curl(1) NAME curl - transfer a URL SYNOPSIS curl [options] [URL...] DESCRIPTION curl is a tool to transfer data from or to a server, using one of the supported protocols (HTTP, HTTPS, FTP, FTPS, SCP, SFTP, TFTP, DICT, TELNET, LDAP or FILE). The command is designed to work without user interaction. curl offers a busload of useful tricks like proxy support, user authen‐ tication, FTP upload, HTTP post, SSL connections, cookies, file trans‐ fer resume and more. As you will see below, the number of features will make your head spin! [...] -A/--user-agent (HTTP) Specify the User-Agent string to send to the HTTP server. Some badly done CGIs fail if this field isn't set to "Mozilla/4.0". To encode blanks in the string, surround the string with single quote marks. This can also be set with the -H/--header option of course. If this option is set more than once, the last one will be the one that's used.