Python Web Crawlers and “getting” html source code

前端 未结 4 1120
不知归路
不知归路 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:30

    An Example with python3 and the requests library as mentioned by @leoluk:

    pip install requests
    

    Script req.py:

    import requests
    
    url='http://localhost'
    
    # in case you need a session
    cd = { 'sessionid': '123..'}
    
    r = requests.get(url, cookies=cd)
    # or without a session: r = requests.get(url)
    r.content
    

    Now,execute it and you will get the html source of localhost!

    python3 req.py

提交回复
热议问题