Web Scraping Yellow Pages with Python | Subscriber request using Scrapy and Xpath

Pubblicato il: 01 gennaio 1970
sul canale di: jobstr
724
12

Scraping Yellow Pages.
A demonstration of finding selectors in Chrome, testing them in the browser developer tools, and then making Scrapy iterate through using accurate and not so accurate selectors.
The main focus of this video is on refining the xpath in the browser developer tools before pasting into your Scrapy spider code.



The full code is here on my GitHub page : https://github.com/RGGH/Scrapy9



: Chapter timings : -


0:00 Introduction - what are we scraping? Why?
0:32 The spider code so far
0:55 The parse method
1:43 Ctrl + F in Chrome
2:57 xpaths : using predicates
4:15 Using "*" wildcard versus "p" or "div" or "span" element
8:22 Finding website addresses
9:55 xpath using 2 predicates
11:28 Updating the Scrapy spider code...adding the selector for 'website'
13:40 Test
14:15 Troubleshooting
14:46 Quick change of selector for website! - No need for 2 predicates!
15:07 Running the spider
15:25 The "."
16:55 Success
17:55 Summary
20:25 Closing comments


If you want more info relating to xpaths, here are some examples plus a great site to check out:

⦿ response.xpath("//div[@class='article']//a/img/@src")
⦿ response.xpath('//a[contains(text(), "Next »")]/@href')
⦿ response.xpath('//div[@class='pibox']/descendant::*/text()')

https://devhints.io/xpath


contains is a really useful one, and it can future proof your spider, as even if the css changes, "Next" should still be spelled the same!


All the best,
Dr Pi.


In questa pagina del sito puoi guardare il video online Web Scraping Yellow Pages with Python | Subscriber request using Scrapy and Xpath della durata di ore minuti seconda in buona qualità , che l'utente ha caricato jobstr 01 gennaio 1970, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 724 volte e gli è piaciuto 12 spettatori. Buona visione!