【发布时间】:2016-10-25 22:34:34
【问题描述】:
使用带有scrapy的xpath执行抓取我没有得到完整的URL
这是我正在查看的网址
使用scrapy shell
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")
只得到一半的href
[<Selector xpath="//*[@id='Thumbnail-Image-Container']/li[1]/a//@href" data=u'http://images.esellerpro.com/2489/I/160/'>]
这是我在浏览器中查看的 html 的 sn-p
<li><a data-medimg="http://images.esellerpro.com/2489/I/160/260/1/medIA01854-GALLERY.jpg" href="http://images.esellerpro.com/2489/I/160/260/1/lrgIA01854-GALLERY.jpg" class="cloud-zoom-gallery Selected" title="OMP FIRST EVO RACE SUIT" rel="useZoom: 'MainIMGLink', smallImage: 'http://images.esellerpro.com/2489/I/160/260/1/lrgIA01854-GALLERY.jpg'"><img src="http://images.esellerpro.com/2489/I/160/260/1/smIA01854-GALLERY.jpg" alt="OMP FIRST EVO RACE SUIT Thumbnail 1"></a></li>
这是来自 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 下载了页面,以确认原始 html 中的 url 是完整的
我还没有测试任何其他构建,但我在 centos 7 中使用了 scrapy 1.2.1 和 2.7
我用谷歌搜索,只找到由于 javascript 动态生成数据而无法获取数据的人,但我的数据在 html 中
【问题讨论】:
标签: python-2.7 xpath web-scraping scrapy