web-scraping
Html Agility Pack. Load and scrape webpage
Much easier to use HtmlWeb. string Url = “http://something”; HtmlWeb web = new HtmlWeb(); HtmlDocument doc = web.Load(Url);
Python Selenium Timeout Exception Catch
Almost of your code is working fine except the Driver.Close(). It should be Driver.close(). The TimeoutException will be thrown when the page is not loaded within specific time. See my code below: from selenium import webdriver from selenium.common.exceptions import TimeoutException Driver = webdriver.Firefox() try: Driver.set_page_load_timeout(1) Driver.get(“http://www.engadget.com”) except TimeoutException as ex: isrunning = 0 print(“Exception has … Read more
Beautiful Soup if Class “Contains” or Regex?
BeautifulSoup supports CSS selectors which allow you to select elements based on the content of particular attributes. This includes the selector *= for contains. The following will return all div elements with a class attribute containing the text ‘listing-col-‘: for EachPart in soup.select(‘div[class*=”listing-col-“]’): print EachPart.get_text()
How can I use Python’s Requests to fake a browser visit a.k.a and generate User Agent? [duplicate]
Provide a User-Agent header: import requests url=”http://www.ichangtou.com/#company:data_000008.html” headers = {‘User-Agent’: ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36’} response = requests.get(url, headers=headers) print(response.content) FYI, here is a list of User-Agent strings for different browsers: List of all Browsers As a side note, there is a pretty useful third-party package called … Read more
How can I download images on a page using puppeteer?
If you want to skip the manual dom traversal you can write the images to disk directly from the page response. Example: const puppeteer = require(‘puppeteer’); const fs = require(‘fs’); const path = require(‘path’); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); page.on(‘response’, async response => { const url … Read more
Managing puppeteer for memory and performance
You probably want to create a pool of multiple Chromium instances with independent browsers. The advantage of that is, when one browser crashes all other jobs can keep running. The advantage of one browser (with multiple pages) is a slight memory and CPU advantage and the cookies are shared between your pages. Pool of puppeteer … Read more
Scrape a webpage and navigate by clicking buttons
Zombie.js and Node.io run on JSDOM, hence your options are either going with JSDOM (or any equivalent wrapper), a headless browser (PhantomJS, SlimerJS) or Cheerio. JSDOM is fairly slow because it has to recreate DOM and CSSOM in Node.js. PhantomJS/SlimerJS are proper headless browsers, thus performances are ok and those are also very reliable. Cheerio … Read more
Is it possible to use Selenium WebDriver to drive PhantomJS?
PhantomJS now includes the GhostDriver project. You are also suggested to use PhantomJS directly or with a convenience library such as CasperJS. CasperJS is specifically designed to make it easy to do sequential operations to web pages, perfect for many automation tasks. Disclaimer: I am the author of PhantomJS. Edit: As noted in Nick’s answer, … Read more
Android Web Scraping with a Headless Browser [closed]
Ok after 2 weeks I admit defeat and are using a workaround which works great for me at the moment. The problem: It is too difficult to port HTMLUnit to Android (or at least with my level of expertise). I am sure its a worthwhile project (and not that time consuming for experienced java programmer) … Read more