你好我想知道是否可以连接到http主机(例如google.com)并下载网页源码?提前致谢。 最佳答案 Usingurllib2todownloadapage.Google将阻止此请求,因为它会尝试阻止所有机器人。将用户代理添加到请求中。importurllib2user_agent='Mozilla/5.0(Macintosh;U;IntelMacOSX10_6_4;en-US)AppleWebKit/534.3(KHTML,likeGecko)Chrome/6.0.472.63Safari/534.3'headers={'Use