| Start |
|---|
| Scraping using the Scrapy framework First you have to set up a new Scrapy project. Enter a directory where you’d like to store your code and run: To scrape we need a spider. Spiders define how a certain site will be scraped. Here’s the code for a spider that follows the links to the top voted questions on StackOverflow and scrapes some data from each page (source (opens new window)): Save your spider classes in the Now you can use your spider. For example, try running (in the project's directory): |
Basic example of using requests and lxml to scrape some data |
| Maintaining web-scraping session with requests It is a good idea to maintain a web-scraping session (opens new window) to persist the cookies and other parameters. Additionally, it can result into a performance improvement because |
| Scraping using Selenium WebDriver Some websites don’t like to be scraped. In these cases you may need to simulate a real user working with a browser. Selenium launches and controls a web browser. Selenium can do much more. It can modify browser’s cookies, fill in forms, simulate mouse clicks, take screenshots of web pages, and run custom JavaScript. |
Scraping using BeautifulSoup4 |
| Modify Scrapy user agent Sometimes the default Scrapy user agent ( For example |
| Simple web content download with urllib.request The standard library module A similar module is also available in Python 2 (opens new window). |
| Scraping with curl imports: Downloading:
Parsing: RemarksUseful Python packages for web scraping (alphabetical order)Making requests and collecting data |
Read Article
https://develop.horje.com/learn/1434/reference