15874103329
V2EX  ›  问与答

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

  •  1
     
  •   15874103329 · Dec 22, 2018 · 1766 views
    This topic created in 2723 days ago, the information mentioned may be changed or developed.

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

    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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1593 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 16:33 · PVG 00:33 · LAX 09:33 · JFK 12:33
    ♥ Do have faith in what you're doing.