Last active
July 7, 2020 17:51
-
-
Save jroquejr/750ca124098b71e9573d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scrapy.spider import BaseSpider | |
| # Requires this patch: | |
| # https://github.com/joehillen/scrapy/commit/6301adcfe9933b91b3918a93387e669165a215c9 | |
| from scrapy.selector import PyQuerySelector | |
| class DmozSpiderPyQuery(BaseSpider): | |
| name = "pyquery" | |
| allowed_domains = ["dmoz.org"] | |
| start_urls = [ | |
| "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/", | |
| "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/" | |
| ] | |
| def parse(self, response): | |
| pq = PyQuerySelector(response) | |
| sites = pq('ul li') | |
| for site in sites: | |
| title = pq(site).find('a').text() | |
| link = pq(site).find('a').attr.href | |
| desc = pq(site).text() | |
| print title, link, desc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment