Python Web Crawlers and “getting” html source code

前端 未结 4 1110
不知归路
不知归路 2020-12-24 13:53

So my brother wanted me to write a web crawler in Python (self-taught) and I know C++, Java, and a bit of html. I\'m using version 2.7 and reading the python library, but I

4条回答
  •  半阙折子戏
    2020-12-24 14:11

    If you are using Python > 3.x you don't need to install any libraries, this is directly built in the python framework. The old urllib2 package has been renamed to urllib:

    from urllib import request
    
    response = request.urlopen("https://www.google.com")
    # set the correct charset below
    page_source = response.read().decode('utf-8')
    print(page_source)
    

提交回复
热议问题