Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 scrapy:xpath未返回@href的完整url_Python 2.7_Xpath_Web Scraping_Scrapy - Fatal编程技术网

Python 2.7 scrapy:xpath未返回@href的完整url

Python 2.7 scrapy:xpath未返回@href的完整url,python-2.7,xpath,web-scraping,scrapy,Python 2.7,Xpath,Web Scraping,Scrapy,使用xpath和scrapy执行scrape我没有得到完整的URL 这是我正在查看的url 使用刮壳 scrapy shell "http://www.ybracing.com/omp-ia01854-omp-first-evo-race-suit.html" 我从shell中执行以下xpath选择 sel.xpath("//*[@id='Thumbnail-Image-Container']/li[1]/a//@href") 只拿到一半的钱 [<Selector xpath="//*

使用xpath和scrapy执行scrape我没有得到完整的URL

这是我正在查看的url

使用刮壳

scrapy shell "http://www.ybracing.com/omp-ia01854-omp-first-evo-race-suit.html"
我从shell中执行以下xpath选择

sel.xpath("//*[@id='Thumbnail-Image-Container']/li[1]/a//@href")
只拿到一半的钱

[<Selector xpath="//*[@id='Thumbnail-Image-Container']/li[1]/a//@href" data=u'http://images.esellerpro.com/2489/I/160/'>]
[]
下面是我在浏览器中看到的html片段

  • 这是wget的

    <li><a data-medimg="http://images.esellerpro.com/2489/I/513/0/medIA01838_GALLERY.JPG" href="http://images.esellerpro.com/2489/I/513/0/lrgIA01838_GALLERY.JPG" class="cloud-zoom-gallery Selected" title="OMP DYNAMO RACE SUIT" rel="useZoom: 'MainIMGLink', smallImage: 'http://images.esellerpro.com/2489/I/513/0/lrgIA01838_GALLERY.JPG'"><img src="http://images.esellerpro.com/2489/I/513/0/smIA01838_GALLERY.JPG" alt="OMP DYNAMO RACE SUIT Thumbnail 1" /></a></li>            
    
  • 我尝试改变xpath以获得相同的结果,但仍然得到相同的结果

    是什么导致了这种情况,我能做些什么来解决它呢?我希望理解,而不是有人帮我修改xpath

    关于页面本身的一些想法我禁用了javascript,以查看js是否生成了一半的url,但不是。我还下载了带有wget的页面,以确认URL在原始html中是否完整

    我还没有测试过任何其他版本,但我在centos 7中使用了scrapy 1.2.1和2.7

    我在谷歌上搜索过,只找到那些由于javascript动态生成数据而无法抓取数据的人,但我的数据通过使用

    sel.xpath("//*[@id='Thumbnail-Image-Container']/li[1]/a//@href")
    
    您将获得一个
    选择器
    实例列表,其中
    数据
    字段仅显示其所有内容的前几个字节(因为它可能很长)

    要以字符串形式检索内容(而不是
    选择器
    实例),您需要使用
    .extract
    .extract\u first

    >>> print(sel.xpath("//*[@id='Thumbnail-Image-Container']/li[1]/a//@href").extract_first())
    http://images.esellerpro.com/2489/I/160/260/1/lrgIA01854-GALLERY.jpg
    

    谢谢,这就很好地解释了
    >>> print(sel.xpath("//*[@id='Thumbnail-Image-Container']/li[1]/a//@href").extract_first())
    http://images.esellerpro.com/2489/I/160/260/1/lrgIA01854-GALLERY.jpg