我得到所有锚链接而不是scrapy中的特定链接

时间:2015-10-12 18:24:55

标签: python xpath web-scraping scrapy

我正在使用 scrapy 1.0.3 。这是我的蜘蛛文件代码,

BOOL WINAPI CAM_EnumCameraEx(BOOL bSynchronized, char **ppCameraList, long lMaxCamera, long lMaxCharacter);

但是,我得到所有锚链接和所有标题。我哪里错了?

提前致谢!

1 个答案:

答案 0 :(得分:0)

您必须通过添加一个点来制作XPath表达式特定于上下文的。另外,我认为你应该使用id="job_listings"

遍历quelist = response.xpath('//div[@id="job_listings"]//a') for que in quelist: item = XxxItem() item['title'] = que.xpath('.//h4/text()').extract() item['link'] = que.xpath('@href').extract() yield item 内的链接
<form>
John's Birthday (YYYY-MM-DD):
<input type=text name=jhbd value=0><br>
Jake's Birthday (YYYY-MM-DD):
<input type=text name=jkbd value=0><br>
<input type=submit>
</form>

$john_bd = $_POST['jhbd'];
$jake_bd = $_POST['jkbd'];
$today = date("Y/m/d");
$interval_jh = $john_bd ->diff($today);
$interval_jk = $jake_bd ->diff($today);


echo "There are".$interval_jh->days."days until John's birthday ";
echo "There are".$interval_jk->days."days until Jake's birthday ";
if ($john_bd > $jake_bd){
echo "John is older";
}
elseif ($jake_bd > $john_bd) {
echo "Jake is older";
}
else "Both Jake and John are twins!";