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 Wikipedia1 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

相关推荐
小趴蔡ha2 小时前
03 NumPy 入门:机器学习中的数组和矩阵
python·线性代数·机器学习·numpy
m0_519196402 小时前
【设计模式】java的习题
开发语言·python
王老师青少年编程3 小时前
2026年全国青少年信息素养大赛算法应用主题赛C++赛项【决赛】模拟卷(汇总)
c++·模拟卷·2026年·青少年信息素养大赛·算法应用主题赛·决赛
pt10433 小时前
网络自动化Python课程:Git版本控制基础入门与实验演示
网络·python·自动化
circuitsosk3 小时前
不止于API调用:大模型推理加速与云原生服务化部署指南
python·云原生·agent·vllm·推理加速·大模型部署·ensorrt-llm
萌动的小火苗3 小时前
深度神经网络中,梯度消失和梯度爆炸的根本原因是什么?有哪些解决方法?【文末含面试万能总结】
人工智能·python·深度学习·神经网络·dnn
卷无止境3 小时前
当Python遇上并发:concurrent.futures的核心逻辑与实战技巧
后端·python
卷无止境3 小时前
编程语言里到底有没有经济学规律?
后端·python
思麟呀3 小时前
C++(八):文件系统库+并行算法
开发语言·c++
天才测试猿12 小时前
2026软件测试面试八股文(含答案+文档)
自动化测试·软件测试·python·功能测试·测试工具·面试·职场和发展