V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
15874103329
V2EX  ›  问与答

[求助] 如何提取出网页标签内所有的属性值

  •  1
     
  •   15874103329 · 2018-12-22 12:16:22 +08:00 · 877 次点击
    这是一个创建于 1952 天前的主题,其中的信息可能已经有所发展或是发生改变。

    代码是这样的,要如何改动啊

    import requests from pyquery import PyQuery as pq from urllib.parse import urlencode import re

    def dizhi(): headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3573.0 Safari/537.36'} data = { 'q': '微信群', 'typeall': '1', 'suball': '1', 'timescope': 'custom:2018 - 12 - 20 - 0: 2018 - 12 - 22 - 0', 'Refer': 'g' } url = 'https://s.weibo.com/weibo/%25E5%25AE%259D%25E5%25A6%2588%25E7%25BE%25A4?' + urlencode(data) wangzhi = requests.get(url,headers = headers) return wangzhi.text

    def jiexi(html): doc = pq(html) item = doc('.m3 li') print(item('img').attr('src'))

    def main(): html = dizhi() jiexi(html)

    if name == 'main': main()

    打印结果:

    //ww4.sinaimg.cn/thumb150/475ee913ly1fydb7js7inj20orcmvx6q.jpg

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2928 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 13:51 · PVG 21:51 · LAX 06:51 · JFK 09:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.