Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Requests.get显示与Chrome不同的HTML';s开发工具_Python_Html_Web Scraping_Python Requests_Jupyter Notebook - Fatal编程技术网

Python Requests.get显示与Chrome不同的HTML';s开发工具

Python Requests.get显示与Chrome不同的HTML';s开发工具,python,html,web-scraping,python-requests,jupyter-notebook,Python,Html,Web Scraping,Python Requests,Jupyter Notebook,我正在使用python(特别是jupyter笔记本)开发一个web抓取工具,它可以抓取一些不动产页面并保存价格、地址等数据 对于我挑选的其中一个页面,它工作得很好,但当我尝试刮取此页面时:(抱歉,该页面是捷克语的,但实际内容现在不那么重要)使用reguests.get()我得到以下结果: Sreality.cz•现实是一个内莫维托斯蒂z celéČR 窗口。uuu insp=窗口。uuu insp | |[]; __普什督察(['wid',821249485]); __推送督察([“虚拟页面

我正在使用python(特别是jupyter笔记本)开发一个web抓取工具,它可以抓取一些不动产页面并保存价格、地址等数据

对于我挑选的其中一个页面,它工作得很好,但当我尝试刮取此页面时:(抱歉,该页面是捷克语的,但实际内容现在不那么重要)使用reguests.get()我得到以下结果:


Sreality.cz•现实是一个内莫维托斯蒂z celéČR
窗口。uuu insp=窗口。uuu insp | |[];
__普什督察(['wid',821249485]);
__推送督察([“虚拟页面]);
(功能(){
函数ldinsp(){if(typeof window.\uu inspld!=“undefined”)返回;window.\uu inspld=1;var insp=document.createElement('script');insp.type='text/javascript';insp.async=true;insp.id=“inspsync”;insp.src=('https:'==document.location.protocol?'https':'http'))+'://cdn.inspectlet.com/inspectlet.js';var x=document.getElementsByTagName('script')[0];x.parentNode.insertBefore(insp,x);};
setTimeout(ldinsp,500);document.readyState!=“完成”?(window.attachEvent?window.attachEvent('onload',ldinsp):window.addEventListener('load',ldinsp,false)):ldinsp();
})();
(功能(){
试一试{
//Při Přesměrovánína hashbang URL(IE8-9)ztrácíme推荐人,
//克特尔耶·波切尼·波切尼统计局局长(kterýje potřeba pro správnépočtánístatistik)。
if(window.sessionStorage){//někdo může mít DOM storage zakázaný
var l=document.createElement('a');
l、 href=document.referer;
var refererHostName=l.hostname;
if(window.location.hostname!=refererHostName){
window.sessionStorage.setItem('referer',l.href);
}
}
//Starýandroid(<4.0)诉kombinaci s angularemšpatněpracuje s hashem v URL。
//Považuje ho za součást query případněpath。
//纳塔科夫·扎伊泽克·布德梅电视台,内比尔。
if(parseInt((/android(\d+)/.exec(window.navigator.userAgent.toLowerCase())| |[])[1],10)<4){
var hrefwhithouthashbang=window.location.href.replace(‘/#!’,‘);
var hashIndex=hrefwhithouthashbang.indexOf('#');
如果(hashIndex!=-1){
window.location.replace(hrefwhithouthashbang.substring(0,hashIndex));
}
}
}捕获(e){}
})();
load(null,{poi:true,pano:true})
login.cfg({
serviceId:“sreality”
});
if(window.DOT){
var dotCfg={
服务:'sreality'
};
if(window.SrealityABTest&&window.SrealityABTest.getVariant()){
dotCfg.abtest=window.SrealityABTest.getVariant();
}
DOT.cfg(dotCfg);
}

如果您最终需要该页面上的数据,那么使用selenium和BeautifulSoup可以非常轻松地获得它。它提供了公寓的所有链接

from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome()

driver.get("https://www.sreality.cz/hledani/prodej/byty/brno?stari=mesic")
soup = BeautifulSoup(driver.page_source,"html.parser")
driver.quit()

for title in soup.select(".text-wrap"):
    num = "https://www.sreality.cz" + title.select_one(".title").get('href')
    print(num)

正如您所想,您的爬虫程序没有执行javascript代码,这将使页面看起来像chrome渲染中的页面。您需要使用代理来为您执行代码。你应该检查飞溅物是否有碎屑或硒。