Thursday, 21 August 2014

Web Scraping data from different sites


I am looking for a few ideas on how can I solve a design problem I'm going to be faced with building a web scraper to scrape multiple sites. Writing the scraper(s) is not the problem, matching the data from different sites (which may have small differences) is.

For the sake of being generic assume that I am scraping something like this from two or more different sites:

    public class Data {
        public int id;
        public String firstname;
        public String surname;
        ....
    }

If i scrape this from two different sites, I will encounter the situation where I could have the following:

Site A: id=100, firstname=William, surname=Doe

Site B: id=1974, firstname=Bill, surname=Doe

Essentially, I would like to consider these two sets of data the same (they are the same person but with their name slightly different on each site). I am looking for possible design solutions that can handle this.

The only idea I've come up with is scraping the data from a third location and using it as a reference list. Then when I scrape site A or B I can, over time, build up a list of failures and store them in a list for each scraper so that it can know (if i find id=100 then i know that the firstname will be William etc). I can't help but feel this is a rubbish idea!

If you need any more info, or if you think my description is a bit naff, let me know!

Thanks,

DMcB


Source: http://stackoverflow.com/questions/23970057/web-scraping-data-from-different-sites

Wednesday, 20 August 2014

Scrape Data Point Using Python


I am looking to scrape a data point using Python off of the url http://www.cavirtex.com/orderbook .

The data point I am looking to scrape is the lowest bid offer, which at the current moment looks like this:

<tr>
 <td><b>Jan. 19, 2014, 2:37 a.m.</b></td>
 <td><b>0.0775/0.1146</b></td>
 <td><b>860.00000</b></td>
 <td><b>66.65 CAD</b></td>
</tr>

The relevant point being the 860.00 . I am looking to build this into a script which can send me an email to alert me of certain price differentials compared to other exchanges.

I'm quite noobie so if in your explanations you could offer your thought process on why you've done certain things it would be very much appreciated.

Thank you in advance!

Edit: This is what I have so far which will return me the name of the title correctly, I'm having trouble grabbing the table data though.

import urllib2, sys
from bs4 import BeautifulSoup

site= "http://cavirtex.com/orderbook"
hdr = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(site,headers=hdr)
page = urllib2.urlopen(req)
soup = BeautifulSoup(page)
print soup.title



Here is the code for scraping the lowest bid from the 'Buying BTC' table:

from selenium import webdriver

fp = webdriver.FirefoxProfile()
browser = webdriver.Firefox(firefox_profile=fp)
browser.get('http://www.cavirtex.com/orderbook')

lowest_bid = float('inf')
elements = browser.find_elements_by_xpath('//div[@id="orderbook_buy"]/table/tbody/tr/td')

for element in elements:
    text = element.get_attribute('innerHTML').strip('<b>|</b>')
    try:
        bid = float(text)
        if lowest_bid > bid:
            lowest_bid = bid
    except:
        pass

browser.quit()
print lowest_bid

In order to install Selenium for Python on your Windows-PC, run from a command line:

pip install selenium (or pip install selenium --upgrade if you already have it).

If you want the 'Selling BTC' table instead, then change "orderbook_buy" to "orderbook_sell".

If you want the 'Last Trades' table instead, then change "orderbook_buy" to "orderbook_trades".

Note:

If you consider performance critical, then you can implement the data-scraping via URL-Connection instead of Selenium, and have your program running much faster. However, your code will probably end up being a lot "messier", due to the tedious XML parsing that you'll be obliged to apply...

Here is the code for sending the previous output in an email from yourself to yourself:

import smtplib,ssl

def SendMail(username,password,contents):
    server = Connect(username)
    try:
        server.login(username,password)
        server.sendmail(username,username,contents)
    except smtplib.SMTPException,error:
        Print(error)
    Disconnect(server)

def Connect(username):
    serverName = username[username.index("@")+1:username.index(".")]
    while True:
        try:
            server = smtplib.SMTP(serverDict[serverName])
        except smtplib.SMTPException,error:
            Print(error)
            continue
        try:
            server.ehlo()
            if server.has_extn("starttls"):
                server.starttls()
                server.ehlo()
        except (smtplib.SMTPException,ssl.SSLError),error:
            Print(error)
            Disconnect(server)
            continue
        break
    return server

def Disconnect(server):
    try:
        server.quit()
    except smtplib.SMTPException,error:
        Print(error)

serverDict = {
    "gmail"  :"smtp.gmail.com",
    "hotmail":"smtp.live.com",
    "yahoo"  :"smtp.mail.yahoo.com"
}

SendMail("your_username@your_provider.com","your_password",str(lowest_bid))

The above code should work if your email provider is either gmail or hotmail or yahoo.

Please note that depending on your firewall configuration, it may ask your permission upon the first time you try it...



Source: http://stackoverflow.com/questions/21217034/scrape-data-point-using-python

Sunday, 17 August 2014

PDF Scraping: Making Modern File Formats More Accessible

Data scraping is the process of automatically sorting through information contained on the internet inside html, PDF or other documents and collecting relevant information to into databases and spreadsheets for later retrieval. On most websites, the text is easily and accessibly written in the source code but an increasing number of businesses are using Adobe PDF format (Portable Document Format: A format which can be viewed by the free Adobe Acrobat software on almost any operating system. See below for a link.). The advantage of PDF format is that the document looks exactly the same no matter which computer you view it from making it ideal for business forms, specification sheets, etc.; the disadvantage is that the text is converted into an image from which you often cannot easily copy and paste. PDF Scraping is the process of data scraping information contained in PDF files. To PDF scrape a PDF document, you must employ a more diverse set of tools.

There are two main types of PDF files: those built from a text file and those built from an image (likely scanned in). Adobe's own software is capable of PDF scraping from text-based PDF files but special tools are needed for PDF scraping text from image-based PDF files. The primary tool for PDF scraping is the OCR program. OCR, or Optical Character Recognition, programs scan a document for small pictures that they can separate into letters. These pictures are then compared to actual letters and if matches are found, the letters are copied into a file. OCR programs can perform PDF scraping of image-based PDF files quite accurately but they are not perfect.

Once the OCR program or Adobe program has finished PDF scraping a document, you can search through the data to find the parts you are most interested in. This information can then be stored into your favorite database or spreadsheet program. Some PDF scraping programs can sort the data into databases and/or spreadsheets automatically making your job that much easier.

Quite often you will not find a PDF scraping program that will obtain exactly the data you want without customization. Surprisingly a search on Google only turned up one business, (the amusingly named ScrapeGoat.com http://www.ScrapeGoat.com) that will create a customized PDF scraping utility for your project. A handful of off the shelf utilities claim to be customizable, but seem to require a bit of programming knowledge and time commitment to use effectively. Obtaining the data yourself with one of these tools may be possible but will likely prove quite tedious and time consuming. It may be advisable to contract a company that specializes in PDF scraping to do it for you quickly and professionally.

Let's explore some real world examples of the uses of PDF scraping technology. A group at Cornell University wanted to improve a database of technical documents in PDF format by taking the old PDF file where the links and references were just images of text and changing the links and references into working clickable links thus making the database easy to navigate and cross-reference. They employed a PDF scraping utility to deconstruct the PDF files and figure out where the links were. They then could create a simple script to re-create the PDF files with working links replacing the old text image.

A computer hardware vendor wanted to display specifications data for his hardware on his website. He hired a company to perform PDF scraping of the hardware documentation on the manufacturers' website and save the PDF scraped data into a database he could use to update his webpage automatically.

PDF Scraping is just collecting information that is available on the public internet. PDF Scraping does not violate copyright laws.

PDF Scraping is a great new technology that can significantly reduce your workload if it involves retrieving information from PDF files. Applications exist that can help you with smaller, easier PDF Scraping projects but companies exist that will create custom applications for larger or more intricate PDF Scraping jobs.

Source:http://ezinearticles.com/?PDF-Scraping:-Making-Modern-File-Formats-More-Accessible&id=193321

Monday, 30 June 2014

Usefulness of Web Scraping Services

For any business or organization, surveys and market research play important roles in the strategic decision-making process. Data extraction and web scraping techniques are important tools that find relevant data and information for your personal or business use. Many companies employ people to copy-paste data manually from the web pages. This process is very reliable but very costly as it results to time wastage and effort. This is so because the data collected is less compared to the resources spent and time taken to gather such data.

Nowadays, various data mining companies have developed effective web scraping techniques that can crawl over thousands of websites and their pages to harvest particular information. The information extracted is then stored into a CSV file, database, XML file, or any other source with the required format. After the data has been collected and stored, data mining process can be used to extract the hidden patterns and trends contained in the data. By understanding the correlations and patterns in the data; policies can be formulated and thereby aiding the decision-making process. The information can also be stored for future reference.

The following are some of the common examples of data extraction process:

• Scrap through a government portal in order to extract the names of the citizens who are reliable for a given survey.

• Scraping competitor websites for feature data and product pricing

• Using web scraping to download videos and images for stock photography site or for website design

Automated Data Collection

It is important to note that web scraping process allows a company to monitor the website data changes over a given time frame. It also collects the data on a routine basis regularly. Automated data collection techniques are quite important as they help companies to discover customer trends and market trends. By determining market trends, it is possible to understand the customer behavior and predict the likelihood of how the data will change.

The following are some of the examples of the automated data collection:

• Monitoring price information for the particular stocks on hourly basis

• Collecting mortgage rates from the various financial institutions on the daily basis

• Checking on weather reports on regular basis as required

By using web scraping services it is possible to extract any data that is related to your business. The data can then be downloaded into a spreadsheet or a database for it to be analyzed and compared. Storing the data in a database or in a required format makes it easier for interpretation and understanding of the correlations and for identification of the hidden patterns.

Through web scraping it is possible to get quicker and accurate results and thus saving many resources in terms of money and time. With data extraction services, it is possible to fetch information about pricing, mailing, database, profile data, and competitors data on a consistent basis. With the emergence of professional data mining companies outsourcing your services will greatly reduce your costs and at the same time you are assured of high quality services.

Source:http://ezinearticles.com/?Usefulness-of-Web-Scraping-Services&id=7181014

Monday, 9 June 2014

Internet marking is the finest method of increment of popularity in commerce

In today’s world key to any business is right kind of marketing strategy that needs to be implemented for the success of any entrepreneurial project. One of the fastest growing ways is to get the listing of your company in top search engines. SEO is one of the ways which can help in increasing or diverting the traffic on any website. People should understand the search result of their website is displayed on the World Wide Web. Different search engines work in different ways by providing different ranking to websites according to the search of the people.

This is why same website has different ranks on different search engines. Basically, website owner provides the keywords to the SEO providers which are appropriate to their business. Business SEO providers make sure the owners are charged low and also providing correct information to search engines. Providing better SEO in Ottawa is the basic feature that service providers aim at, their main motive is to make these services available to all the common people so that they can benefit there business in a better way. A good SEO mostly uses popular sites like Google, Bing, Yahoo, Yellow pages etc.

These SEO companies make sure that the listing of their clients is upgraded by repeated updating and also there ranking reaches top on search engines. Consultations with SEO service provider can be availed for free by the website owners. SEO companies carefully chooses keyword for their clients because it has to be unique and commonly used to make them reach at the top .They do so by carefully analyzing the owners website and competitors website and then the strategy is made to determine the perfect keyword for their clients.

Owner should make sure that the prices charged to him are competitive according to market. Consultation and Analysis are important because the keyword formation is directly dependent on these two parameters if the SEO service provider fails to submit the proper keyword it would result in failure of whole SEO services for the owner.

SEO provider can re create and also modify the keywords for any website. If anyone specifically looking to create a new SEO website for him then the Looking internet marketing company in ottawa specialists can help them in determining a new domain that could be related to the business of the owner. Secondly, good hosting service is provided by them which help a website fast to access by any user. The biggest task for Internet marketing specialist is Link building because it represents more than 80% result of SEO. For any website owner good SEO link building can be good in this competitive world because it attracts the people.

A good SEO developer plays a pivotal role in developing a perfect keyword for the company. Ottawa SEO companies are very famous to deliver their services to the customers at very reasonable prices. SEO services are available online one can visit their websites see the list of services offered by them, read the testimonials of the existing and choose from them pay online and get started.

For further detail about Business seo service in Ottawa please visit the website.

Source:http://blogs.siliconindia.com/businessseo/Business/Internet-marking-is-the-finest-method-of-increment-of-popularity-in-commerce-bid-cf9206bx84461691.html

Monday, 19 May 2014

Bitcoin Mining Company CoinTerra Enters Cloud Mining

Amid rapid changes in the bitcoin mining industry, another bitcoin miner is going into the cloud.

CoinTerra on Monday announced that it will begin offering cloud-based mining services to its customers, becoming the second big miner this month to make the move. As the price of bitcoin has tumbled, it has become increasingly difficult to profitably mine bitcoin, a problem for the miners and the companies catering to them.

As more miners come aboard, the bitcoin algorithm automatically adjusts its difficultly higher. This has sparked an arms race, with miners deploying increasingly powerful computers to stay on top. That has led to a rising spiral of costs. It’s reached the point where it’s become cost-prohibitive for people to mine on their own. Cloud mining, where miners buy contracts from companies like CoinTerra and PeerNova, is emerging as a cheaper option.

CoinTerra, founded nearly a year ago,  will be selling one- and two-year contracts for a range of mining power, from 200 gigahash (small) up to one petahash (big), as well as continuing to sell mining rigs. “We’re catering to basically the entire spectrum out there,” CEO Ravi Iyengar told BitBeat. Through the mining rigs it sells, CoinTerra comprises about 15% of the total mining output, the company said, and it expects to maintain that market share.

As bitcoin has grown, the”hash rate,” a measurement of mining power, has skyrocketed. In September 2013, the entire mining network reached the 1 petahash/second rate, a multiple of 40 times higher than in January 2013. Now CoinTerra will be selling 1 petahash contracts. It’s gotten so big, it’s harder to mine profitably on anything but a very large scale. CoinTerra itself saw sales drop 30% in April. Thus the move into cloud mining.

In the early days of the cryptocurrency, it was possible to mine using desktop computers. As it grew, CPUs gave way to graphics cards, which gave way to generic chips modified for mining, which gave way to chips programmed for a single task called ASICs. It now takes machines with multiple dedicated chips to mine profitably, and increasingly even that kind of computing power doesn’t provide a sufficient return on the investment, given the falling price of bitcoins, the increasing size of the mining community, and the concurrent increasing energy demands, which has emerged as a major roadblock. “Space and power is a big issue,” Mr. Iyengar told BitBeat. “The power required is unlike any other server industry.”

CoinTerra is leasing space at several data centers in the U.S., he said, and has some plans to build its own data center.

The upheaval has resulted in a string of problems for the industry, from bankruptcies to delivery delays to lawsuits. KnCMiner has had problems with deliveries, and branched out into selling rigs that mine for altcoins rather than bitcoin. Butterfly Labs is involved in several lawsuits, and a startup called HashFast Technologies (which is also involved in a lawsuit) on Monday announced that it laid off 50% of its staff. Washington-based Alydian simply went bankrupt as the cloud-based mining business it built couldn’t keep up with the increasing power demands.

“A lot of people got into this space in the mad gold rush,” Mr. Iyengar said, “here you’re trying to combine hardware and software and the whole supply chain associated with a server market.” He likened it to trying to combine Intel, Microsoft, and Dell.

The total computing power is rising at such an exponential rate, that machines have a short productive lifespan. Even a delay of a month or two between the time a customer places an order and the time the machine arrives can severely cut into profits.

Thus the move into the cloud. CoinTerra joins the recently formed PeerNova in offering cloud services.

Source:http://blogs.wsj.com/moneybeat/2014/05/12/bitcoin-mining-company-cointerra-enters-cloud-mining/

Sunday, 17 November 2013

Data scraping tool for non-coding journalists launches

A tool which helps non-coding journalists scrape data from websites has launched in public beta today.

Import.io lets you extract data from any website into a spreadsheet simply by mousing over a few rows of information.

Until now import.io, which we reported on back in April, has been available in private developer preview and has been Windows only. It is now also available for Mac and is open to all.

Although import.io plans to charge for some services at a later date, there will always be a free option.

The London-based start-up is trying to solve the problem of the fact that there is "lots of data on the web, but it's difficult to get at", Andrew Fogg, founder of import.io, said in a webinar last week.

Those with the know-how can write a scraper or use an API to get at data, Fogg said. "But imagine if you could turn any website into a spreadsheet or API."

Uses for journalists

Journalists can find stories in data. For example, if I wanted to do a story on the type of journalism jobs being advertised and the salaries offered, I could research this by looking at various websites which advertise journalism jobs.

If I were to gather the data from four different jobs boards and enter the information manually into a spreadsheet it would take would take hours if not days; if I were to write a screen scraper for each of the sites it would require knowledge and would probably take a couple of hours. Using import.io I can create a single dataset from multiple sources in a few minutes.

I can then search and sort the dataset and find out different facts, such as how many unpaid internships are advertised, or how many editors are currently being sought.

How it works

When you download the import.io application you see a web browser. This browser allows you to enter a URL for any site you want to scrape data from.

To take the example of the jobs board, this is structured data, with the job role, description and salaries displayed.

The first step is to set up 'connectors' and to do this you need to teach the system where the data is on the page. This is done by hitting a 'record' button on the right of the browser window and mousing over a few examples, in this case advertised jobs. You then click 'train rows'.

It takes between two and five examples to teach import.io where all of the rows are, Fogg explained in the webinar.

The next step is to declare the type of data and add column names. For example there may be columns for 'job title', 'job description' and 'salary'. Data is then extracted into the table below the browser window.

Data from different websites can then be "mixed" into a single searchable database.

In the example used in the webinar, Fogg demonstrated how import.io could take data relating to rucksacks for sale on a shopping website. The tool can learn the "extraction pattern", Fogg explained, and apply that to to another product. So rather than mousing over the different rows of sleeping bags advertised, for example, import.io was automatically able to detect where the price and product details were on the page as it had learnt the structure from how the rucksacks were organised. The really smart bit is that the data from all products can then be automatically scraped and pulled into the spreadsheet. You can then search 'shoes' and find the data has already been pulled into your database.

When a site changes its code a screen scraper would become ineffective. Import.io has a "resilience to change", Fogg said. It runs tests twice a day and users get notified of any changes and can retrain a connector.

It is worth noting that a site that has been scraped will be able to detect that import.io has extracted the data as it will appear in the source site's web logs.

Case studies

A few organisations have already used import.io for data extraction. Fogg outlined three.

    British Red Cross

The British Red Cross wanted to create an iPhone app with data from the NHS Choices website. The NHS wanted the charity to use the data but the health site does not have an API.

By using import.io, data was scraped from the NHS site. The app is now in the iTunes store and users can use it to enter a postcode to find hospital information based on the data from the NHS site.

"It allowed them to build an API for a website where there wasn't one," Fogg said.

    Hewlett Packard

Fogg explained that Hewlett Packard wanted to monitor the prices of its laptops on retailers' websites.

They used import.io to scrape the data from the various sites and were able monitor the prices at which the laptops were being sold in real-time.

    Recruitment site

A US recruitment firm wanted to set up a system so that when any job vacancy appeared on a competitor's website, they could extract the details and push that into their Salesforce software. The initial solution was to write scrapers, Fogg said, but this was costly and in the end they gave up. Instead they used import.io to scrape the sites and collate the data.


Source: http://www.journalism.co.uk/news/data-scraping-tool-for-non-coding-journalists-launches/s2/a554002/