账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    为何无法打开这个页面?
    49
    0

    下面的代码打开yahoo.com首页,并输出p标签中的所有文字

    import urllib.request
    import lxml.html
    chaper_url="https://www.yahoo.com/"
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    req = urllib.request.Request(url=chaper_url, headers=headers)
    myString=urllib.request.urlopen(req).read()
    root=lxml.html.document_fromstring(myString)
    txt=root.xpath("//p")
    for etxt in txt:
        print(etxt.text_content())
        

    换个目标: http://www.seek68.cn/bdhxqkml...
    同样的代码结构

    import urllib.request
    import lxml.html
    chaper_url="http://www.seek68.cn/bdhxqkml-7.htm"
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
    req = urllib.request.Request(url=chaper_url, headers=headers)
    myString=urllib.request.urlopen(req).read()
    root=lxml.html.document_fromstring(myString)
    txt=root.xpath("//p")
    for etxt in txt:
        print(etxt.text_content())
        
        

    上面的代码会卡死在 myString=urllib.request.urlopen(req).read()
    为何?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部