Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.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抓取结果与浏览器中的不同_Python_Web Scraping_Beautifulsoup_Selenium Chromedriver_Referrer - Fatal编程技术网

为什么python抓取结果与浏览器中的不同

为什么python抓取结果与浏览器中的不同,python,web-scraping,beautifulsoup,selenium-chromedriver,referrer,Python,Web Scraping,Beautifulsoup,Selenium Chromedriver,Referrer,我可以浏览网页https://www.xiami.com/artist/O9fc383在浏览器中,但当我用chrome驱动程序解析它时,我得到了不同的源代码,如下所示,这样我就无法刮取该页面了,我该怎么办?浏览器中的源没有此表单 ... <form action="//www.xiami.com:443/artist/O9fc383/_____tmd_____/verify/" id="nc-verify-form" method="GET"> ... <script>

我可以浏览网页
https://www.xiami.com/artist/O9fc383
在浏览器中,但当我用chrome驱动程序解析它时,我得到了不同的源代码,如下所示,这样我就无法刮取该页面了,我该怎么办?浏览器中的源没有此表单

...
<form action="//www.xiami.com:443/artist/O9fc383/_____tmd_____/verify/" id="nc-verify-form" method="GET">
...
<script>
    var referrer=document.referrer;
    if (referrer && referrer.indexOf("__tmd__")===-1 ){
        localStorage.x5referer = document.referrer;
    }else{
        localStorage.x5referer = window.location.href;
    }
</script>
。。。
...
var referer=document.referer;
if(referer&&referer.indexOf(“\uu tmd”)=-1){
localStorage.x5referer=document.referer;
}否则{
localStorage.x5referer=window.location.href;
}

您使用什么库进行刮取?如果您使用beautiful soup或urllib,则无法刮取javascript生成的代码。你将不得不使用类似硅元素的东西

可能是HTML是在客户端呈现的,类似于单页应用程序。可能重复尝试过的HTML,不同于浏览器和抓取的结果。我使用selenium以便获得源代码,我猜当chrome驱动程序访问页面时,它会加载不同的内容,如何在浏览器中进行模拟?这篇文章或其副本应该有助于您浏览网页
https://www.xiami.com/artist/O9fc383
,然后尝试用硒刮擦,检查它们对我是否相同?