tutorial-pybr2023-raspando-.../code/parsing-xpath.py
2023-10-23 21:49:33 -03:00

17 lines
423 B
Python

import scrapy
class PythonGroupsSpider(scrapy.Spider):
name = "pythongroups"
start_urls = [
"http://python.org.br",
]
def parse(self, response):
groups = response.xpath('//div[contains(@class, "card")]')
for group in groups:
yield {
"name": group.xpath('.//h4/text()').get(),
"links": group.xpath('.//a/@href').getall(),
}