I'm brand new to Python and web scraping and cannot figure out what is wrong with my code for the life of me. Is it because I'm scraping just one element and not a list? I've checked my XPaths so many times. Right now I'm just trying to scrape the parcel number.
My code:
html = requests.get("https://jeffersonmo-assessor.devnetwedge.com/parcel/view/01401903003039/2023")
doc = lxml.html.fromstring(html.content)
parcel_info = doc.xpath('//div[@class="panel-body collapse in egfjbbgcdd"]')
parcelNumber = parcel_info.xpath('./td[@class="col-xs-6"]/div[@class="inner-value"]/text_content()')
parcelNumber
I tried the code above and received the "AttibuteError: 'list' object has no attribute 'xpath' message.
doc.xpath()
returns a list of matching elements (even if there is only one). So yes,parcel_info
is a list.parcel_info.xpath...
withparcel_info[0].xpath...
- instead of trying to access.xpath
on theparcel_info
list, accessing it on the first element in the listparcel_info[0]