【发布时间】:2016-08-26 13:53:08
【问题描述】:
尝试从网站检索页面源时,我得到的文本与通过网络浏览器查看相同页面源时完全不同(且更短)的文本。
这个家伙有一个相关的问题,但获得了主页源而不是请求的源 - 我得到了完全陌生的东西。
代码是:
from urllib import request
def get_page_source(n):
url = 'https://www.whoscored.com/Matches/' + str(n) + '/live'
response = request.urlopen(url)
return str(response.read())
n = 1006233
text = get_page_source(n)
这是我在此示例中定位的页面: https://www.whoscored.com/Matches/1006233/live
有问题的 url 包含页面源中的丰富信息,但在运行上述代码时我最终只得到以下内容:
文本 =
b'<html style="height:100%"><head><META NAME="ROBOTS" CONTENT="NOINDEX,
NOFOLLOW"><meta name="format-detection" content="telephone=no"><meta
name="viewport" content="initial-scale=1.0"><meta http-equiv="X-
UA-Compatible" content="IE=edge,chrome=1"></head><body style="margin:0px;
height:100%"><iframe src="/_Incapsula_Resource?CWUDNSAI=24&
xinfo=0-12919260-0 0NNY RT(1462118673272 111) q(0 -1 -1 -1) r(0 -1)
B12(4,315,0) U2&incident_id=276000100045095595-100029307305590944&edet=12&
cinfo=04000000" frameborder=0 width="100%" height="100%" marginheight="0px"
marginwidth="0px">Request unsuccessful. Incapsula incident ID:
276000100045095595-100029307305590944</iframe></body></html>'
这里出了什么问题?即使没有发送重复请求,服务器也能检测到机器人吗?如果可以,如何检测?有没有办法解决?
【问题讨论】:
标签: python html url web-scraping