Home > other >  xpath correct using scrapy
xpath correct using scrapy

Time:07-24

import scrapy
from scrapy.http import Request

class PushpaSpider(scrapy.Spider):
    name = 'test'
    start_urls = ['https://ap-rk.com/advokat-panfilov-vladimir-vladimirovich-moskva-otzyvy-telefon-adres-chasy-raboty-foto/']

    def parse(self, response):
        website=response.xpath("//td//strong[contains(.,'Официальный сайт:')]/following-sibling::td/text()").get()
        yield{
            'website':website
        }

I want to try to extract link but they will give me nothing these is the page link https://ap-rk.com/advokat-panfilov-vladimir-vladimirovich-moskva-otzyvy-telefon-adres-chasy-raboty-foto/

CodePudding user response:

Nobody can stop you using a complex solution like scrapy, when the same result can be achieved in 2 lines of code (well, 3):

import pandas as pd

dfs = pd.read_html('https://ap-rk.com/advokat-panfilov-vladimir-vladimirovich-moskva-otzyvy-telefon-adres-chasy-raboty-foto/')
dfs[0]

This returns:

0   1
0   NaN Телефон:  7 (495) 646-0697
1   Рабочий адрес:  Москва
2   NaN г. Москва, ул. Бутырский вал, дом № 68, офис №403
3   Специализация:  корпоративное право предпринимательское право
4   Об адвокате:    NaN
5   Информация: Адвокатская палата: Республики Башкортостан Но...
6   Электронная почта:  [email protected]
7   Официальный сайт:   https://chelovekizakon.ru

EDIT: as my attempt to suggesting a lesser complexity solution made the OP angry, here is the correct XPATH to locate the url in question:

"//td/strong[text()='Официальный сайт:']/parent::td//following-sibling::td"
  • Related