how to extract <code> content from html using scrapy - xpath
I inspect the following content that I want to extract.
<code style="display: none" id="bpr-guid-1441788">
{"companyDetails":{"com.linkedin.voyager.jobs.JobPostingCompany":{"companyResolutionResult":{"entityUrn":"urn:li:fs_normalized_company:166973","name":"World Wildlife Fund","logo":{"image":{"com.linkedin.voyager.common.MediaProcessorImage":{"id":"/p/3/000/093/367/1651958.png"}},"type":"LOGO_LEGACY"}},"company":"urn:li:fs_normalized_company:166973"}},"entityUrn":"urn:li:fs_normalized_jobPosting:324588733","formattedLocation":"Bozeman, Montana","jobState":"LISTED","description":{"attributes":[{"start":572,"length":1,"type":{"com.linkedin.pemberly.text.LineBreak":{}}},{"start":0,"length":574,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":574,"length":1,"type":{"com.linkedin.pemberly.text.LineBreak":{}}},{"start":574,"length":2,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":576,"length":18,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":594,"length":316,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":910,"length":134,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":1044,"length":160,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":1204,"length":342,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":1546,"length":270,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":594,"length":1222,"type":{"com.linkedin.pemberly.text.List":{"ordered":false}}},{"start":1817,"length":1,"type":{"com.linkedin.pemberly.text.LineBreak":{}}},{"start":1834,"length":1,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":1835,"length":147,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":1982,"length":129,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":2111,"length":130,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":2241,"length":92,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":2333,"length":189,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":1835,"length":687,"type":{"com.linkedin.pemberly.text.List":{"ordered":false}}},{"start":2522,"length":1,"type":{"com.linkedin.pemberly.text.LineBreak":{}}},{"start":2522,"length":1,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2522,"length":2,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":2524,"length":12,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2524,"length":66,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":2590,"length":1,"type":{"com.linkedin.pemberly.text.LineBreak":{}}},{"start":2590,"length":1,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2590,"length":2,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":2592,"length":9,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2592,"length":10,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":2602,"length":17,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2619,"length":12,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2631,"length":78,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2602,"length":108,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":2710,"length":88,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2710,"length":89,"type":{"com.linkedin.pemberly.text.ListItem":{}}},{"start":2602,"length":197,"type":{"com.linkedin.pemberly.text.List":{"ordered":false}}},{"start":2799,"length":177,"type":{"com.linkedin.pemberly.text.Bold":{}}},{"start":2799,"length":177,"type":{"com.linkedin.pemberly.text.Paragraph":{}}},{"start":2976,"length":0,"type":{"com.linkedin.pemberly.text.Paragraph":{}}}],"text":"World Wildlife Fund (WWF), the world’s leading conservation organization, seeks a Data Analyst. Under the direction of the supervisor, this position is responsible for providing data synthesis and analysis for the Northern Great Plains (NGP). S/he will assist the NGP program in communicating its goals and successes through the development of data synthesis products and developing statistical interpretation of existing and new datasets, with a focus on informing grassland conservation. S/he will develop products to disseminate information to NGP staff and partners. \n \n Responsibilities Provide data synthesis and interpretation for existing and new datasets to support grassland conservation goals. Work with existing datasets to develop new ways of interpreting the data and communicating it to partners. Work with new datasets to help answer key science questions as outlined by the Program Manager. Given the list of science priorities for the program, develop methods for answering pressing questions using the best available data. Develop spatial data for use in projects. Collect and process datasets for use by NGP staff and partners, as needed and in partnership with the GIS Specialist. Support NGP Program by developing in-depth knowledge of grassland conservation and researching and developing skills in other approaches necessary to ensure success of WWF’s conservation strategies in the region. Build knowledge through research to keep up to date with the state of the art knowledge and apply the knowledge to WWF projects. The candidate will report to the Program Manager. S/he will also maintain strong relationships with the Managing Director, Deputy Director, NGO partner organizations, federal, state and provincial agency planning personnel and corporate and foundations staff at WWF-US. \n Qualifications A Master of Science Degree in Biostatistics, Biology, Conservation Biology, Zoology, Ecology, Wildlife Management, or a related field, is required 4+ years of experience in spatial analysis and data synthesis is required. A PhD will substitute for 3 years of work experience. Substantial and demonstrated experience in spatial analysis; data synthesis; and managing an independent work program is required Experience in biodiversity conservation and grassland-focused spatial datasets is preferred Candidates should have a strong commitment to the mission, goals, and values of WWF, good interpersonal and relationship-building skills, energy and enthusiasm, and high ethical standards. \n Please Note: This is a 2-year position based in Bozeman, Montana. \n To Apply: Please visit our Careers Page, job#17065, to submit an online application including resume and cover letter Due to the high volume of applications we are not able to respond to inquiries via phone As an EOE/AA employer, WWF will not discriminate in its employment practices due to an applicant’s race, color, religion, sex, national origin, and veteran or disability status."},"applyMethod":{"com.linkedin.voyager.jobs.OffsiteApply":{"applyStartersPreferenceVoid":true,"companyApplyUrl":"https://careers-wwfus.icims.com/jobs/1727/data-analyst---17065/job"}},"title":"Data Analyst","listedAt":1496950791000}
</code>
I tried several different ways to extract the content, especially the longest text part, such as
body.xpath('//code[#id="bpr-guid-1441788"]/text()').extract()
But there is no response, the return of scrapy is null.
Anyone can help me out?
Related
Is there any sentiment forum dataset for unsupervised training available?
I recently finished a machine learning course and would like to make a forum sentiment analysis tool, to apply it in stock-related forums. The idea is to: Capture (text mining) users with their comments, and evaluate their comment's sentiment (positive, negative, neutral). Capture what happens (stock market) after those comments, and assign a weight to the user accordingly (bigger weight if the user's sentiments is spot-on and the market follows the same direction) Use the comments as a tool to predict market direction. Actually, I do this myself (pay attention on forums) plus my own technical analysis and the obligatory due diligence, and it has been working very well for me. I just wanted to try to automate it a little bit and maybe even allow a program to play with some of my accounts (paper trading first, and if it performs decently assign some money in a real account) This would be my first machine learning project (just as a proof-of-concept) so any comments would be very kindly appreciated. The biggest problem that I find is that I would like to make an unsupervised training, and I need a sample dataset to do the training. Question: Is there any known forum-sentiment dataset available to be used for unsupervised training? I've found several sentiment datasets (twitter, imbd, amazon reviews) but they are very specific to their niche (short messages, movies, products...) but I'm looking for something more general.
Since you are looking for an unsupervised approach you can use any set of data that matches your "real case scenario". Text mining and sentiment analysis are are often tailored to the problem at hand so it is easy to start directly with the real data. The best approach is to built a scraper that grabs directly the forum posts that you want to analyze. You can build the scraper easily enough with Python (beautifulsoup/selenium). Online is full of nice tutorial eg: https://www.dataquest.io/blog/web-scraping-tutorial-python/
Meaning of Business Intelligence
The word "Intelligence" has two meanings: 1: the ability to learn, apply knowledge, or think abstractly. 2: a: information concerning an enemy or organization or group with the task of gathering such information. b: news or information of any kind. In the term Business Intelligence, which one is the meaning of Intelligence? 1 or 2? Are there any articles on web about this distinction?
This is not a programming question. However, Business Intelligence systems are systems that are able to gather information, process them by analyzing the patterns and at the end of the day, forecast.
Well, the way we use it (with Cognos BI) is in the second sense. Business intelligence is the information about your organisation and Cognos BI is one way to gather and present that information in a way that's easily adaptable and useful. Having moved from BIRT to Cognos last year, I have to admit that, despite the increased cost of the product, things are a lot easier to do. It always seemed to me that BIRT was very little "BI" and mostly "RT" :-) Sorry to sound like an advertorial back there, I was just stating how we use the term.
Business intelligence (BI) refers to computer-based techniques used in spotting, digging-out, and analyzing business data, such as sales revenue by products and/or departments or associated costs and incomes It is pretty clear to me that retrieve and analyze data is a way to learn, apply knowledge, or think abstractly. Yes business is about competition. Competition is about fighting. So IMHO, two are valid
Trust metrics and related algorithms
I'm trying to learn more about trust metrics (including related algorithms) and how user voting, ranking and rating systems can be wired to stiffle abuse. I've read abstract articles and papers describing trust metrics but haven't seen any actual implementations. My goal is to create a system that allows users to vote on other users and the content of other users and with those votes and related meta-data, determine if those votes can be applied to a users level or popularity. Have you used or seen some sort of trust system within a social graph? How did it work and what were its areas of strength and weaknesses?
I'm reading the book Programming Collective Intelligence. From the description: Want to tap the power behind search rankings, product recommendations, social bookmarking, and online matchmaking? This fascinating book demonstrates how you can build Web 2.0 applications to mine the enormous amount of data created by people on the Internet. The algorithms in the book are implemented in python. I've just started reading the book so I don't know if it can help solve your problem, but it's worth taking a look.
Resources related to data-mining and gaming on social networks
I'm interested in the problem of patterning mining among players of social networking games. For example detecting cheaters of a game, given a company's user database. So far I have been following the usual recipe for a data mining project: construct a data warehouse that aggregates significant information select a classifier, and train it with a subsectio of records from the warehouse validate classifier with another test set lather, rinse, repeat Surprisingly, I've found very little in this area regarding literature, best practices, etc. I am hoping to crowdsource the information gathering problem here. Specifically what I'm looking for: What classifiers have worked will for this type of pattern mining (it seems highly temporal, users playing games, users receiving rewards, users transferring prizes etc). Are there any highly agreed upon attributes specific to social networking / gaming data? What is a practical amount of information that should be considered? One problem I've run into is data overload, where queries and data cleansing may take days to complete. Related to point above, what hardware resources are required to produce results? I've found it difficult to estimate the amount of computing power I will require for production use. It has become apparent that a white box in the corner does not have enough horse-power for such a project. Are companies generally resorting to cloud solutions? Are they buying clusters? Basically, any resources (theoretical, academic, or practical) about implementing a social networking / gaming pattern-mining program would be very much appreciated. Thanks.
I am looking for the same kind of resources, here are some things I found that I consider pretty interesting, hope you can take advantage of it, please if you discover more resources let me know. Here they are: http://techcrunch.com/2010/04/06/turiya-media-games/ http://www.kdnuggets.com/2010/08/video-tutorial-christian-thurau-data-mining-in-games.html?k10n21 http://www.gamasutra.com/view/feature/2816/better_game_design_through_data_.php This is in portuguesse but is excelent: http://thiagofalcao.info/
How does the Amazon Recommendation feature work?
What technology goes in behind the screens of Amazon recommendation technology? I believe that Amazon recommendation is currently the best in the market, but how do they provide us with such relevant recommendations? Recently, we have been involved with similar recommendation kind of project, but would surely like to know about the in and outs of the Amazon recommendation technology from a technical standpoint. Any inputs would be highly appreciated. Update: This patent explains how personalized recommendations are done but it is not very technical, and so it would be really nice if some insights could be provided. From the comments of Dave, Affinity Analysis forms the basis for such kind of Recommendation Engines. Also here are some good reads on the Topic Demystifying Market Basket Analysis Market Basket Analysis Affinity Analysis Suggested Reading: Data Mining: Concepts and Technique
It is both an art and a science. Typical fields of study revolve around market basket analysis (also called affinity analysis) which is a subset of the field of data mining. Typical components in such a system include identification of primary driver items and the identification of affinity items (accessory upsell, cross sell). Keep in mind the data sources they have to mine... Purchased shopping carts = real money from real people spent on real items = powerful data and a lot of it. Items added to carts but abandoned. Pricing experiments online (A/B testing, etc.) where they offer the same products at different prices and see the results Packaging experiments (A/B testing, etc.) where they offer different products in different "bundles" or discount various pairings of items Wishlists - what's on them specifically for you - and in aggregate it can be treated similarly to another stream of basket analysis data Referral sites (identification of where you came in from can hint other items of interest) Dwell times (how long before you click back and pick a different item) Ratings by you or those in your social network/buying circles - if you rate things you like you get more of what you like and if you confirm with the "i already own it" button they create a very complete profile of you Demographic information (your shipping address, etc.) - they know what is popular in your general area for your kids, yourself, your spouse, etc. user segmentation = did you buy 3 books in separate months for a toddler? likely have a kid or more.. etc. Direct marketing click through data - did you get an email from them and click through? They know which email it was and what you clicked through on and whether you bought it as a result. Click paths in session - what did you view regardless of whether it went in your cart Number of times viewed an item before final purchase If you're dealing with a brick and mortar store they might have your physical purchase history to go off of as well (i.e. toys r us or something that is online and also a physical store) etc. etc. etc. Luckily people behave similarly in aggregate so the more they know about the buying population at large the better they know what will and won't sell and with every transaction and every rating/wishlist add/browse they know how to more personally tailor recommendations. Keep in mind this is likely only a small sample of the full set of influences of what ends up in recommendations, etc. Now I have no inside knowledge of how Amazon does business (never worked there) and all I'm doing is talking about classical approaches to the problem of online commerce - I used to be the PM who worked on data mining and analytics for the Microsoft product called Commerce Server. We shipped in Commerce Server the tools that allowed people to build sites with similar capabilities.... but the bigger the sales volume the better the data the better the model - and Amazon is BIG. I can only imagine how fun it is to play with models with that much data in a commerce driven site. Now many of those algorithms (like the predictor that started out in commerce server) have moved on to live directly within Microsoft SQL. The four big take-a-ways you should have are: Amazon (or any retailer) is looking at aggregate data for tons of transactions and tons of people... this allows them to even recommend pretty well for anonymous users on their site. Amazon (or any sophisticated retailer) is keeping track of behavior and purchases of anyone that is logged in and using that to further refine on top of the mass aggregate data. Often there is a means of over riding the accumulated data and taking "editorial" control of suggestions for product managers of specific lines (like some person who owns the 'digital cameras' vertical or the 'romance novels' vertical or similar) where they truly are experts There are often promotional deals (i.e. sony or panasonic or nikon or canon or sprint or verizon pays additional money to the retailer, or gives a better discount at larger quantities or other things in those lines) that will cause certain "suggestions" to rise to the top more often than others - there is always some reasonable business logic and business reason behind this targeted at making more on each transaction or reducing wholesale costs, etc. In terms of actual implementation? Just about all large online systems boil down to some set of pipelines (or a filter pattern implementation or a workflow, etc. you call it what you will) that allow for a context to be evaluated by a series of modules that apply some form of business logic. Typically a different pipeline would be associated with each separate task on the page - you might have one that does recommended "packages/upsells" (i.e. buy this with the item you're looking at) and one that does "alternatives" (i.e. buy this instead of the thing you're looking at) and another that pulls items most closely related from your wish list (by product category or similar). The results of these pipelines are able to be placed on various parts of the page (above the scroll bar, below the scroll, on the left, on the right, different fonts, different size images, etc.) and tested to see which perform best. Since you're using nice easy to plug and play modules that define the business logic for these pipelines you end up with the moral equivalent of lego blocks that make it easy to pick and choose from the business logic you want applied when you build another pipeline which allows faster innovation, more experimentation, and in the end higher profits. Did that help at all? Hope that give you a little bit of insight how this works in general for just about any ecommerce site - not just Amazon. Amazon (from talking to friends that have worked there) is very data driven and continually measures the effectiveness of it's user experience and the pricing, promotion, packaging, etc. - they are a very sophisticated retailer online and are likely at the leading edge of a lot of the algorithms they use to optimize profit - and those are likely proprietary secrets (you know like the formula to KFC's secret spices) and guaarded as such.
This isn't directly related to Amazon's recommendation system, but it might be helpful to study the methods used by people who competed in the Netflix Prize, a contest to develop a better recommendation system using Netflix user data. A lot of good information exists in their community about data mining techniques in general. The team that won used a blend of the recommendations generated by a lot of different models/techniques. I know that some of the main methods used were principal component analysis, nearest neighbor methods, and neural networks. Here are some papers by the winning team: R. Bell, Y. Koren, C. Volinsky, "The BellKor 2008 Solution to the Netflix Prize", (2008). A. Töscher, M. Jahrer, “The BigChaos Solution to the Netflix Prize 2008", (2008). A. Töscher, M. Jahrer, R. Legenstein, "Improved Neighborhood-Based Algorithms for Large-Scale Recommender Systems", SIGKDD Workshop on Large-Scale Recommender Systems and the Netflix Prize Competition (KDD’08) , ACM Press (2008). Y. Koren, "The BellKor Solution to the Netflix Grand Prize", (2009). A. Töscher, M. Jahrer, R. Bell, "The BigChaos Solution to the Netflix Grand Prize", (2009). M. Piotte, M. Chabbert, "The Pragmatic Theory solution to the Netflix Grand Prize", (2009). The 2008 papers are from the first year's Progress Prize. I recommend reading the earlier ones first because the later ones build upon the previous work.
I bumped on this paper today: Amazon.com Recommendations: Item-to-Item Collaborative Filtering Maybe it provides additional information.
(Disclamer: I used to work at Amazon, though I didn't work on the recommendations team.) ewernli's answer should be the correct one -- the paper links to Amazon's original recommendation system, and from what I can tell (both from personal experience as an Amazon shopper and having worked on similar systems at other companies), very little has changed: at its core, Amazon's recommendation feature is still very heavily based on item-to-item collaborative filtering. Just look at what form the recommendations take: on my front page, they're all either of the form "You viewed X...Customers who also viewed this also viewed...", or else a melange of items similar to things I've bought or viewed before. If I specifically go to my "Recommended for You" page, every item describes why it's recommended for me: "Recommended because you purchased...", "Recommended because you added X to your wishlist...", etc. This is a classic sign of item-to-item collaborative filtering. So how does item-to-item collaborative filtering work? Basically, for each item, you build a "neighborhood" of related items (e.g., by looking at what items people have viewed together or what items people have bought together -- to determine similarity, you can use metrics like the Jaccard index; correlation is another possibility, though I suspect Amazon doesn't use ratings data very heavily). Then, whenever I view an item X or make a purchase Y, Amazon suggests me things in the same neighborhood as X or Y. Some other approaches that Amazon could potentially use, but likely doesn't, are described here: http://blog.echen.me/2011/02/15/an-overview-of-item-to-item-collaborative-filtering-with-amazons-recommendation-system/ A lot of what Dave describes is almost certainly not done at Amazon. (Ratings by those in my social network? Nope, Amazon doesn't have any of my social data. This would be a massive privacy issue in any case, so it'd be tricky for Amazon to do even if they had that data: people don't want their friends to know what books or movies they're buying. Demographic information? Nope, nothing in the recommendations suggests they're looking at this. [Unlike Netflix, who does surface what other people in my area are watching.])
I don't have any knowledge of Amazon's algorithm specifically, but one component of such an algorithm would probably involve tracking groups of items frequently ordered together, and then using that data to recommend other items in the group when a customer purchases some subset of the group. Another possibility would be to track the frequency of item B being ordered within N days after ordering item A, which could suggest a correlation.
As far I know, it's use Case-Based Reasoning as an engine for it. You can see in this sources: here, here and here. There are many sources in google searching for amazon and case-based reasoning.
If you want a hands-on tutorial (using open-source R) then you could do worse than going through this: https://gist.github.com/yoshiki146/31d4a46c3d8e906c3cd24f425568d34e It is a run-time optimised version of another piece of work: http://www.salemmarafi.com/code/collaborative-filtering-r/ However, the variation of the code on the first link runs MUCH faster so I recommend using that (I found the only slow part of yoshiki146's code is the final routine which generates the recommendation at user level - it took about an hour with my data on my machine). I adapted this code to work as a recommendation engine for the retailer I work for. The algorithm used is - as others have said above - collaborative filtering. This method of CF calculates a cosine similarity matrix and then sorts by that similarity to find the 'nearest neighbour' for each element (music band in the example given, retail product in my application). The resulting table can recommend a band/product based on another chosen band/product. The next section of the code goes a step further with USER (or customer) based collaborative filtering. The output of this is a large table with the top 100 bands/products recommended for a given user/customer
Someone did a presentation at our University on something similar last week, and referenced the Amazon recommendation system. I believe that it uses a form of K-Means Clustering to cluster people into their different buying habits. Hope this helps :) Check this out too: Link and as HTML.