Full text
SCRAPING NEWS SITES AND SOCIAL NETWORKS FOR PREJUDICE TERM ANALYSIS Pedro Rangel Henriques, Cristiana Araújo, Isabel Ermida and Idalete Dias Universidade do Minho, Portugal ABSTRACT Computer-Mediated Communication (CMC) has paved the way for new patterns of linguistic aggravation. Hidden behind the screen, anyone can comment on any other person's opinion using an offensive or injurious tone. Besides, types of prejudice such as homophobia, sexism, racism, xenophobia, anticlericalism, body/addiction shaming, among others, are easily found nowadays in social networks and other forms of interactive Web sites potentiated by Web 2.0. This increasing violence deserves further investigation from different academic perspectives, among which Sociolinguistics stands out. This paper is concerned with the design and development of a set of computer-based tools to collect articles and posts with the respective comment threads that can be used as sources to extract prejudice terms and allow different analyses to be conducted. These prejudice terms were devised using a sociolinguistic variable stratification approach. We will focus on the filters used to extract the relevant fields from the Web pages collected, and on the converters used to adapt formats to obtain a common format for information representation. We will also introduce the statistical analysis processor that explores the extracted data, in that format, to output a set of indicators. KEYWORDS Information Extraction, Social Web, Web Scraping, Computer-Mediated Communication 1. INTRODUCTION Our team's project deals with hate speech online, i.e., the expression of prejudice and discrimination on the Internet. It aims to identify recurrent words, idioms and constructions, as well as communicative routines and patterns of pragmatic interaction, that may serve as a basis for abuse detection. The object of analysis is online social platforms, such as Facebook, YouTube, Twitter, and Web journal comment boards, where participants often engage in expressing opinions that are ideology-laden and biased against a range of social groups and subjects. The project aims to build and annotate a comparable corpus of online texts, on a range of similar topics but in different languages, namely Portuguese and English. This contrastive analysis will hopefully allow us to assess the socio-cultural similarities and differences of the two linguistic contexts in an admittedly globalized society. Annotation of the corpus will begin by metadata, which will stratify the texts according to sociolinguistic variables such as age, gender, ethnicity, nationality and social class. This will pave the way for studies in language variation. Structural taggers will be inserted next, providing information about the morpho-syntactic organization of the texts, which may carry ideological intent. Finally, content taggers will help design a descriptive ontology of the corpora that will lend itself to various interpretive tasks. The results of this extended study will help refine informatics tools of control and detection on institutional levels, including automatic identification of situations of risk and abuse online. The research question we intend to answer in this paper can be stated as follows: How to integrate into a single corpus posts with comments, containing prejudice terms, extracted from different social networks and news sites? 16th International Conference on Applied Computing 2019 179
In this context, the paper focuses on the software paraphernalia that is under development to support the extraction from multiple sources of hate speech sentences. The tools and techniques we have used may not be new, but the novelty and the strength of our work so far is that we have managed to integrate all available tools into a unified approach. Thus, we have succeeded in tackling the various problems which the different sources posed and can now choose the appropriate tool and extraction method for each different source. Besides, we have managed to integrate the partial results into a global analysis tool that is automated and available through a simple Web interface. Additionally - and crucially - we have also started to successfully collect the metadata of each extraction. Section 2 presents a set of keywords for text extraction, devised according to a sociolinguistic variable stratification method. Section 3 introduces the approach followed to execute the tasks involved in the extraction. Then Sections 4 and 5 discuss in detail the extractors of material from sources such as social networks and newspaper sites. Section 6 presents the system of detection and analysis of discursive prejudices. Finally, Section 7 presents the conclusions and future work. 2. SOCIOLINGUISTIC STRATIFICATION OF ONLINE PREJUDICE AND DISCRIMINATION: KEYWORDS FOR DATA EXTRACTION The project aims to analyze the linguistic forms and strategies of prejudice in Computer-Mediated Communication (CMC). As CMC is a phenomenon that brings together multiple manifestations, not only at the linguistic level (morphology, syntax, lexical semantics), but also (inter)actionally and pragmatically, it is important to cross it with the sociolinguistic variables it involves. With this caveat in mind, our team devised a keyword table for data extraction, at the very outset of the project. This table covers the following elements: (i) different types of prejudice; (ii) the corresponding sociolinguistic variables they target; and (iii) the various keywords and expressions which, in English and Portuguese, are deemed typical lexical signals of prejudice expression. Ten types of prejudice were considered: sexism, ageism, racism, nationalism, classism, homophobia, anticlericalism, ideological shaming, body shaming, and addiction shaming. The former five correspond to the following classic sociolinguistic variables, respectively: gender, age, race (and ethnicity), nationality, and social class (Labov, 2001). Prejudice types six to eight correspond to the following identity categories: sexual identity, religious identity, and ideological/political identity (Coupland, 2007). Finally, items nine and ten correspond to physical identity and behavioral identity. For each of these parameters a list of keywords, especially slurs, was developed, to help scrape the Web for texts that express prejudice. This approach will cater for discursive and pragmatic analyses, with a view to identifying emerging ideological communities (Lambert, 2007). The aim is to know what actors - both active and passive, victimizers and victimized - populate the virtual world of marginalization and conflict, and what their recurrent identities and attitudes are in terms of linguistic expression. The approach for extracting and analyzing comment boards is presented in Section 3. 3. EXTRACTION AND ANALYSIS - THE APPROACH As previously mentioned, the project aims to analyze verbal interaction in online comment boards. At this stage, we are extracting data from two types of online platforms: newspaper sites and social networks (YouTube and Facebook), in the Portuguese language. Before starting the extraction process, it is necessary to find news articles and publications that can trigger biased and discriminatory comments. Our approach to searching across platforms has been to use the keywords (see Section 2) in the platform search to find the publications that contain those keywords. After finding them we start the extraction. It is important to note that in addition to extracting comments we also extract the news articles, publications, audio-visual texts, etc., that triggered the thread of comments. As the goal of the project is to construct a corpus for linguists and other specialists to use in their research, we find it appropriate to keep the source text that gave rise to the verbal interaction. The news articles found in the newspaper sites will then be looked for in the respective newspaper Facebook page in order to extract the post and the comment thread from there. In general, we have discovered that the same news article has a greater number of comments on ISBN: 978-989-8533-95-1 © 2019 180
the newspaper's Facebook page, compared to the newspaper site, in the case of Portuguese newspapers. In the newspaper “Correio da Manhã” (a Portuguese tabloid), we are only going to extract the comment threads on the newspaper's Facebook page because the contents of the comment threads on the newspaper site have recently stopped being accessible. Our extraction and comment analysis schema is shown in Figure 1. Figure 1. General Extraction Schema1 Figure 1 is a simplified schema that contains all the steps from the extraction to the analysis of the comments. Extractors will scrape web pages (Newspaper, Facebook, YouTube) and as a result we obtain a file, which can be in a range of formats, such as HTML, JSON, CSV, etc., depending on each extractor. Subsequently the extracted files will be converted into a standard format resorting to the File Converters. In this case, we have chosen JSON as the standard format. Finally, comment threads in JSON format will be examined according to a Statistical Analysis to evaluate the Frequency of occurrence of the keywords which reveal prejudice and discrimination in the comments. The results of this analysis are saved in a CSV file. In the following sections we will explain all these processes in more detail. 4. EXTRACTING POSTS/COMMENTS FROM ONLINE SOCIAL NETWORKS Extracting the posts and comment threads from Web social networks (YouTube and Facebook) is carried out using two freely available online tools. A detailed outline of the steps of this extraction is shown in Figure 2. 1 All the icons of Figures 1, 2 and 5 were taken from the website: “The Noun Project” (https://thenounproject.com/). Accessed: 2019-04- 10. 16th International Conference on Applied Computing 2019 181
Figure 2. YouTube and Facebook Extraction Schema On YouTube the extraction takes place using the application YouTube Comment Scraper2. To start the extraction, it is necessary to enter the publication link and the application automatically extracts the thread with all comments in JSON and CSV format. In our case, the thread was extracted in JSON format, to standardize all extractions. In Figure 3, a fragment of a comment thread extracted from YouTube is exhibited. Figure 3. Comment thread extracted from YouTube (fragment) According to Klostermann (2015), the fields extracted in each comment thread are: id - ID of the comment; user - name or nickname of the author of the comment; date - publishing date of the comment; timestamp - time an event is logged by a computer, not the time of the event itself; commentText - text of the comment; likes - number of likes on the comment; hasReplies - whether the comment has replies; numberOfReplies - number of replies; replies - whether the comment is a reply to another comment (in threaded conversations). 2 YouTube Comment Scraper: http://ytcomments.klostermann.ca/. ISBN: 978-989-8533-95-1 © 2019 182
It is important to note that this application only extracts the comment thread and does not extract any information regarding the publication. Extraction on Facebook is done with the tool Netvizz3, a Facebook application that can be found by typing the name into the main Facebook search box. To extract the data from a page, it is only necessary to enter the page ID and date scope. The result of the extraction is a CSV file that in this case contains the comment thread and publication information (Rieder, 2013). According to Rieder (2013), the fields extracted by Netvizz are: position - postnumber_commentnumber (e.g. 0_0 for the first comment on the first post); post_id - ID of the post; post_by - author of the post; post_text - text of the post; post_published - publishing date of the post; comment_id - ID of the comment; comment_by - author of the comment (column no longer in use, remains for compatibility); is_reply - whether the comment is a reply to another comment (in threaded conversations); comment_message - text of the comment; comment_published - publishing date of the comment; comment_like_count - number of likes on the comment; attachment_type - attachment type (eg: animated_image_share); attachment_url - attachment URL. As the results of Facebook extraction are obtained in CSV format, it is necessary to convert them into JSON format. The transformation of files extracted from Facebook in CSV format to JSON format is performed by a script in Python. For each line of the CSV file, the Converter forms a name/value pair, where the field name corresponds to its column name and value is the extraction result of the respective field. For example, “comment_message”: “Os casamentos de Sto António são para casais (homem/mulher) e não para pares (2 do mesmo sexo)” [“Saint Anthony’s weddings are for man/woman couples, not for same-sex pairs”], where “comment_message” is a column name and “Os casamentos de Sto António são para casais (homem/mulher) e não para pares (2 do mesmo sexo)” corresponds to the extraction result. The JSON generated by the converter is listed in Figure 4. In Section 5 we will explain the extractors of newspaper sites in detail. Figure 4. Comment thread extracted from Facebook in JSON (fragment) 5. EXTRACTING ARTICLES/COMMENTS FROM NEWSPAPER WEB PAGES The comment thread and article extraction from the newspaper web pages is performed by Python scripts, one to extract the article from the newspaper, and another script to extract comments related to the article. A detailed outline of the steps of this extraction is shown in Figure 5. The newspaper sites are dynamic Web pages, that is, they assemble content that comes from different sources. They use scripts that perform functions such as: database information, article comments, links to other news, links to different topics/news categories, etc., and fill the page with content from different sources in the 3 Netvizz: https://apps.facebook.com/netvizz 16th International Conference on Applied Computing 2019 183
visualization moment (i.e. when the page is requested). This means that the page content is not fully included in the original static page. An example of content that is integrated into the newspaper article page is the comment thread and, therefore, its extraction becomes more difficult. This is noticeable when we click on “inspect element”: on the newspaper page we can see we can see the HTML code with the comment thread, but when we click on “view page source” we cannot find the HTML code with the comment thread. The explanation for this omission is that “view page source” only shows the content that was found on the server. However, the final DOM (Document Object Model) that is rendered by the browser can be very different, because the JavaScript that is compiled when opening the page manipulates the DOM and integrates content that comes from the different sources. This leads us to see the HTML code with the comment thread when we click on “inspect element” (Prutsachainimmit and Nadee, 2018). Figure 5. Newspaper Extraction Schema Faced with this difficulty, it was necessary to understand the different types of scraping techniques avaliable and how we would apply them to carry out the extraction. Scraping can be either static or dynamic. Static scraping bypasses JavaScript and searches the server's Web pages without the help of a browser. This type of scraping extracts exactly all the information we see when we click on “view page source”. Static scraping works using two Python packages: Requests4 to find web pages and Beautiful Soup5 to parse HTML pages. Dynamic scraping uses a real browser and allows the JavaScript on the page to run. Subsequently, it queries the DOM to extract the content we are looking for. There are also cases where it is necessary to automate the browser, that is, to simulate the steps a user takes to obtain the content needed. Dynamic scraping works by using the Selenium6 Python package to automate the browser and interactively interact with the DOM. Selenium requires a WebDriver7 (the browser is automated) for the Internet browser (Mitchell, 2015; Jarmul and Lawson, 2017). In our case, the most adequate scraping technique is the dynamic one because the content of the comments comes from another source, as explained above. Dynamic scraping will allow us to find the information that comes from another source, but we also use static scraping to extract the information we want after finding it with dynamic scraping.Figure 6 shows a fragment of the Newspaper Article extractor (in this example we are extracting news from the Portuguese newspaper “Sol”), which, as already mentioned, uses dynamic scraping (Selenium and WebDriver) and static scraping (Beautiful Soup). 4 Requests: https://2.python-requests.org/en/master/ 5 Beautiful Soup: https://www.crummy.com/software/BeautifulSoup/bs4/doc/ 6 Selenium: https://www.seleniumhq.org 7 WebDriver: https://www.seleniumhq.org/projects/webdriver/ ISBN: 978-989-8533-95-1 © 2019 184
All the data we want to extract from the newspaper article is on the source page, but we have decided to use both types of scraping, so to make it applicable to most types of content. In lines 5-14 we use dynamic scraping to open and load the page, and close cookie windows, etc. that appear when the page loads; and we use static scraping, lines 15-29, to search for the elements and extract the information. The WebDriver we used was Geckodriver as it is the driver used for the connection to Firefox (line 5). The driver runs the browser and opens the link to the page we entered in the driver.get function (line 6). Subsequently, we look for the tag <div> whose id is article-full and store in the variable dados (lines 13 and 14). This tag contains all the HTML code with the information that we want to extract. Figure 6. Extractor of Newspaper Article (fragment) Then we use Beautiful Soup to parse this HTML and save the HTML code returned by the Selenium, already converted to Beautiful Soup, within the variable soup (line 15). The soup variable is the tree root parsed from the HTML page that will allow us to browse and search elements in the tree. Within this tree we will look only for the specific elements that we want to extract: title - title of the article; subtitle - subtitle of the article; date - date on which the article was published; shares - number of article shares in social networks (when applicable); article - text of the article. For example, to extract the title of the article we will look in the tree for <div> whose class is “large-9 medium-8 column artic_content” (which contains the header and body of the article) and store it in the variable header. Within the variable header we will look for the <header> tag, and within that tag search for the <h1> tag and save the text (title of the article) found in the <h1> tag in the variable titleN. This extractor stores information extracted in JSON format (see Figure 7). Figure 7. Extraction of Newspaper Article (example) 16th International Conference on Applied Computing 2019 185
The comment thread extractor is shown in Figure 8 and, similarly to the previous extractor, it also uses dynamic and static scraping to perform the extraction. In this case, dynamic scraping plays a very important role because the comment thread is imported from an external source, that is, it is not in the source code of the main page. On the other hand, it is also important when there is an extensive list of comments, as it is necessary to simulate a user clicking on the button in order to see the remaining comments, otherwise the extractor only extracts the comments that are visible (open) in the HTML page at that time. The search and extraction logic of this extractor is very similar to the previous one, the main difference is that it opens the main page of the news article (line 6), then it will look for the url of the sub-page (in the <iframe> tag in the attribute src) that contains the comment thread (lines 9-11), and finally, opens it to access its information (line 12). When the list of comments is extensive, a button is displayed to click and see the remaining comments. The simulation of that click as if it were a user is performed in lines 16-22. Finally, in lines 27-29 the list of the comment thread is searched and stored in the variable listComments. The result of this extraction is an extensive HTML code that contains all the comments. The next step is to filter the extracted information and convert it to JSON format. To achieve this, we constructed a Text Filter and JSON Converter, in Flex, which looks for the information that we want to extract and saves it in JSON format. This phase poses significant challenges: one being that HTML is very verbose and so it takes several steps to extract a simple field; another is the occurrence of responses to nested comments within each other, which makes it difficult to identify where responses end up, given various levels of nesting. Figure 8. Extractor of the Newspaper Comment Thread (fragment) JSON generated by the application has the same fields as JSON extracted on YouTube. Figure 9 shows the JSON result of the HTML extraction. Figure 9. Newspaper Comment Thread in JSON format (fragment of a comment) ISBN: 978-989-8533-95-1 © 2019 186
It is important to point out that this whole extraction process (newspaper article extractor, comment thread extractor and text filter and JSON converter) is specific to the newspaper “Sol”. This means that for each newspaper it is necessary to create new extractors and a new text filter and JSON Converter, since each newspaper has a different web page. In Section 6 the analysis of comments to identify discriminatory and prejudice discourse will be discussed. 6. PREJUDICE DISCOURSE DETECTION AND ANALYSIS It is important to remember that the final objective of the extraction process previously presented is to collect a stream of comment threads to build a comparable linguistic corpus that will be studied mainly in terms of verbal interaction in CMC. After extracting the comments, it is necessary to analyze if the comment thread exhibits a prejudiced and discriminatory stance. To carry out this analysis, we have constructed a Python script that does the statistical analysis for the occurrence of keywords in the comments. This analysis performed by the Python script compares the comment text with the keywords table, which is in JSON format. The code fragment shown in Figure 10 aims to search for the keywords (presented in Section 2) in the comments. When it finds them, it creates a triple analysis with the keyword, the number of occurrences of the keyword and the total number of words that the comment has. Figure 10. Statistical analysis for the occurrence of keywords in the comments (fragment) This script in Python does the statistical analysis by: type of prejudice in a comment thread; frequency with which this concept appears in a particular comment; total number of comments that have keywords out of the total number of comments of the thread; which keywords are present in the comments and how often they appear in the comment thread; which type of prejudice is present in the comment thread; which is the most prevalent prejudice in a comment thread. The analysis that is performed for a file with a comment thread can also be performed for a directory that contains several files with comment threads. The output of the statistical analysis for the occurrence of keywords in the comments is exported to a CSV file. An example of this result is shown in Figure 11. This example corresponds to the JSON sample of YouTube extraction in Figure 3. Figure 11. Result of statistical analysis for the occurrence of keywords in the comments 16th International Conference on Applied Computing 2019 187