Web scraping 错误:使用Puppeter进行Webscraping-无法读取属性';getProperty';未定义的

Web scraping 错误:使用Puppeter进行Webscraping-无法读取属性';getProperty';未定义的,web-scraping,puppeteer,Web Scraping,Puppeteer,我正在尝试在RightMove中为所有返回的搜索项刮取URL。网页为: 我正在使用Puppeter尝试这样做,但不断出现错误“无法读取未定义的属性'getProperty'” 这是我的密码: const puppeteer = require('puppeteer'); async function scrapePropery(URL) { const browser = await puppeteer.launch(); try { const page = await br

我正在尝试在RightMove中为所有返回的搜索项刮取URL。网页为:

我正在使用Puppeter尝试这样做,但不断出现错误“无法读取未定义的属性'getProperty'”

这是我的密码:

const puppeteer = require('puppeteer');

async function scrapePropery(URL)  {
  const browser = await puppeteer.launch();
  try {
  const page = await browser.newPage();
  await page.goto(URL);
  
  const [el] = await page.$x('//*[@id="property-105155516"]/div/div/div[4]/div[1]/div[2]/a');
  const href = await el.getProperty('href')
  const hrefTxt = await href.jsonValue();

  console.log({hrefTxt});

} catch (err) {
    console.error(err.message);
  } finally {

  browser.close();

};
}

scrapePropery('https://www.rightmove.co.uk/property-for-sale/find.html?searchType=SALE&locationIdentifier=REGION%5E61299&insId=2&radius=0.0&minPrice=&maxPrice=&minBedrooms=&maxBedrooms=&displayPropertyType=&maxDaysSinceAdded=&_includeSSTC=on&sortByPriceDescending=&primaryDisplayPropertyType=&secondaryDisplayPropertyType=&oldDisplayPropertyType=&oldPrimaryDisplayPropertyType=&newHome=&auction=false');
我做错了什么?我尝试过删除不同的元素,但一直都会遇到相同的错误,我成功地使用了我在其他网站(如Amazon)上编写的代码(对.getProperty方法中的属性做了一些小的更改),但RightMove没有成功

有什么想法吗?


感谢

此代码的问题在于所使用的xPath不正确,这导致了未定义的响应。

我在页面的html中没有看到该id。感谢QHarr,看起来出现这种情况是因为搜索列表中的第一个属性(我用作id)是一个已更改的特性。我没有注意到这可能是我的问题。。。需要改变方法。谢谢