pythonComputation for the Social Sciences

Introduction to Computation for the Social Sciences Assignment 7

Prof. Dr. Karsten Donnay, Stefan Scholz Winter Term 2018 / 2019

Please solve the exercises below and submit your solutions to our GitHub Classroom until Dec, 18th midnight. Submit all your code in one executable file (py

/ ipynb ) and your list in one delimited text file (csv).

This assignment sheet is graded according to the following scheme: 3 points (fully complete and correct), 2 points (mostly ), 1 point (partly ) and 0 points (hardly). You will get individual feedback in your repository.

Exercise 1: Simple Web Crawler

Web Crawling, i.e. the automated access of Web resources via software, and Web scraping, i.e. the extraction of content from Web resources, are essential techniques to gather data for many analysis tasks in the social sciences. We will implement a very simple Web crawler that starts at a given URL and iteratively accesses all links, more specifically all href-tags in the HTML source code of a Website.

To get an idea how to approach this problem using Python, have a look at the sample implementation of a crawler in the subchapters Traversing a Single Domain and Crawling an Entire Site in the book Web Scraping with Python by Ryan Mitchell. If you search for the book online, you will find a PDF version of it.

Implement an iterative crawler (no recursive calls) that:

  • opens the front page of the German Wikipedia[1] and downloads the html resource

  • parses the html file as a BeautifulSoup object.

  • collects all internal href tags, i.e. only links to other Wikipedia pages on the server de.wikipedia.org

  • opens each of the collected links and parses the returned html resource for additional internal links

    Additionally, your crawler has to meet the following requirements:

  • Consider the Wikipedia front page as the root (level 0) of a tree and the Wikipedia pages linked to on the front page as level 1. Crawl no deeper than level 2!

  • Visit each unique link only once, i.e. disregard links that you traversed before

  • Store all links of the same level in a list, i.e. one list per level.

  • Include links that you encounter more than once in the list of the lowest level (closer to the root) they appear at.

  • Write the lists of links to a CSV file in the format [level ; link_URL].

Finally, submit your solutions by adding your code and csv file in your Git repository within the folder assignment07 > solution. Do not forget to commit and push your solutions afterwards.

1\] https://de.wikipedia.org/wiki/Wikipedia:Hauptseite

相关推荐
财经资讯数据_灵砚智能15 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月19日
大数据·人工智能·python·信息可视化·自然语言处理
财经资讯数据_灵砚智能16 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年5月20日
大数据·人工智能·python·信息可视化·自然语言处理
计算机安禾16 小时前
【c++面向对象编程】第37篇:面向对象设计原则(一):单一职责与开闭原则
开发语言·c++·开闭原则
小明同学0116 小时前
C++后端项目:统一大模型接入 SDK(三)
开发语言·c++
Brilliantwxx16 小时前
【C++】 继承与多态(下)
开发语言·c++
C+++Python16 小时前
C++考试语法知识
开发语言·c++
wuxinyan12316 小时前
工业级大模型学习之路019:LangChain零基础入门教程(第二篇):LLM 模块与模型抽象
人工智能·python·学习·langchain
凯瑟琳.奥古斯特16 小时前
操作系统核心结构解析
java·开发语言·c++·python·职场和发展
麻雀飞吧16 小时前
非 CTP 柜台连接天勤:众期融航易达等网关差异备忘
python
晚霞的不甘16 小时前
CANN 模型转换与适配:从 PyTorch 到 Ascend OM 的完整指南
人工智能·pytorch·python·深度学习