美文网首页
Python不同网络模块网页源代码的获取

Python不同网络模块网页源代码的获取

作者: C_Y_ | 来源:发表于2016-08-07 01:27 被阅读40次

    requests模块

    req=requests.get(url)
    source = req.text
    

    或者使用

    req.content
    

    selenium模块

    driver = webdriver.PhantomJS(desired_capabilities=dcap)
    driver.get(url)
    source = driver.page_source
    

    BeautifulSoup模块

    soup=BeautifulSoup(req.text,'lxml')
    source=soup.content
    webtext=soup.text
    #BeautifulSoup对象的text属性是所有文本内容
    

    urllib模块

    response=urllib.opernner.open(url)
    source = response.read()

    相关文章

      网友评论

          本文标题:Python不同网络模块网页源代码的获取

          本文链接:https://www.haomeiwen.com/subject/vdqlsttx.html