[{"data":1,"prerenderedAt":439},["ShallowReactive",2],{"i-lucide:menu":3,"i-lucide:arrow-up-right":8,"i-lucide:moon":10,"i-lucide:sun":12,"i-lucide:rss":14,"i-simple-icons:github":16,"i-simple-icons:linkedin":18,"post-\u002F2010\u002Fa-python-script-to-fetch-info-from-an-url-regular-expression-matching":21,"surround-\u002F2010\u002Fa-python-script-to-fetch-info-from-an-url-regular-expression-matching":51,"i-lucide:arrow-left":60,"i-lucide:arrow-right":62,"gist-2656905":64},{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":7},0,24,false,"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 5h16M4 12h16M4 19h16\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":9},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M7 7h10v10M7 17L17 7\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":11},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":13},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Ccircle cx=\"12\" cy=\"12\" r=\"4\"\u002F>\u003Cpath d=\"M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41\"\u002F>\u003C\u002Fg>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":15},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M4 11a9 9 0 0 1 9 9M4 4a16 16 0 0 1 16 16\"\u002F>\u003Ccircle cx=\"5\" cy=\"19\" r=\"1\"\u002F>\u003C\u002Fg>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":17},"\u003Cpath fill=\"currentColor\" d=\"M12 .297c-6.63 0-12 5.373-12 12c0 5.303 3.438 9.8 8.205 11.385c.6.113.82-.258.82-.577c0-.285-.01-1.04-.015-2.04c-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729c1.205.084 1.838 1.236 1.838 1.236c1.07 1.835 2.809 1.305 3.495.998c.108-.776.417-1.305.76-1.605c-2.665-.3-5.466-1.332-5.466-5.93c0-1.31.465-2.38 1.235-3.22c-.135-.303-.54-1.523.105-3.176c0 0 1.005-.322 3.3 1.23c.96-.267 1.98-.399 3-.405c1.02.006 2.04.138 3 .405c2.28-1.552 3.285-1.23 3.285-1.23c.645 1.653.24 2.873.12 3.176c.765.84 1.23 1.91 1.23 3.22c0 4.61-2.805 5.625-5.475 5.92c.42.36.81 1.096.81 2.22c0 1.606-.015 2.896-.015 3.286c0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":19,"hidden":20},"\u003Cpath fill=\"currentColor\" d=\"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037c-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85c3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.06 2.06 0 0 1-2.063-2.065a2.064 2.064 0 1 1 2.063 2.065m1.782 13.019H3.555V9h3.564zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0z\"\u002F>",true,{"id":22,"title":23,"body":24,"category":35,"comments":36,"date":37,"description":32,"excerpt":36,"extension":38,"image":36,"meta":39,"navigation":20,"path":40,"readingTime":41,"seo":42,"stem":43,"subtitle":36,"tags":44,"wordCount":33,"__hash__":50},"posts\u002F2010\u002Fa-python-script-to-fetch-info-from-an-url-regular-expression-matching.md","A Python script to fetch info from an URL (Regular expression matching)",{"type":25,"value":26,"toc":31},"minimark",[27],[28,29],"gist",{"id":30},"2656905",{"title":32,"searchDepth":33,"depth":33,"links":34},"",2,[],"Projects",null,"2010-07-04","md",{},"\u002F2010\u002Fa-python-script-to-fetch-info-from-an-url-regular-expression-matching","less than 1 minute",{"title":23,"description":32},"2010\u002Fa-python-script-to-fetch-info-from-an-url-regular-expression-matching",[45,46,47,48,49],"python","script","regex","url","scrape","rlZs2U_sBPqgLmoMU6zBxcOcNJJymoP9yo2Ex7se6j0",[52,56],{"title":53,"path":54,"stem":55,"children":-1},"KÜG rebased '09","\u002F2009\u002Fkug-rebased-09","2009\u002Fkug-rebased-09",{"title":57,"path":58,"stem":59,"children":-1},"43things-tip","\u002F2010\u002F43things-tip","2010\u002F43things-tip",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":61},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m12 19l-7-7l7-7m7 7H5\"\u002F>",{"left":4,"top":4,"width":5,"height":5,"rotate":4,"vFlip":6,"hFlip":6,"body":63},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M5 12h14m-7-7l7 7l-7 7\"\u002F>",{"id":65,"title":66,"body":67,"createdAt":430,"description":32,"extension":38,"files":431,"gistId":30,"meta":432,"navigation":20,"owner":433,"path":434,"seo":435,"stem":436,"url":437,"__hash__":438},"gists\u002Fgists\u002F2656905.md","A script to get specified info from a URL",{"type":25,"value":68,"toc":428},[69,424],[70,71,75],"pre",{"className":72,"code":73,"filename":74,"language":45,"meta":32,"style":32},"language-python shiki shiki-themes github-light github-dark","#!\u002Fusr\u002Fbin\u002Fpython -tt\n\n# A script to get specified info from a URL\n# Author Ando Roots 2010\n# Usage: Specify the parameters with command line options.\n# Usage: .\u002Ffetch_info.py URL Search_pattern_start Search_pattern_end\n# EXAMPLE: Rate.ee number of online users\n# .\u002Ffetch_info.py http:\u002F\u002Fwww.rate.ee\u002F 'amp;act=search\"&gt;\u003Cstrong>' ' &amp;raquo;\u003C\u002Fstrong>'\n\nimport sys\nimport urllib\nimport re\n\n# Fetch the souce code, find and print the information\ndef fetch_info(url, start, end):\n\n  sourceCode = urllib.urlopen(url).read()\n  expression = start + '(.*?)' + end\n\n  # Regular expression matching on the source code of the target URL\n  match = re.compile(expression).search(sourceCode)\n  if match:\n    print match.group(1)\n  else:\n    print 'Did not find a match.'\n  sys.exit(0)\n\ndef main():\n  if len(sys.argv) != 4:\n    print 'A script to get specified info from a URL by A. Roots'\n    print 'Usage: .\u002Ffetch_info.py URL Search_pattern_start Search_pattern_end'\n    sys.exit(1)\n\n  fetch_info(sys.argv[1], sys.argv[2], sys.argv[3])\n  sys.exit(0)\n\nif __name__ == '__main__':\n  main()\n","fetch_info.py",[76,77,78,87,92,98,104,110,116,122,128,133,144,152,160,165,171,184,189,201,225,230,236,247,256,272,280,288,299,304,315,334,342,350,360,365,387,396,401,418],"code",{"__ignoreMap":32},[79,80,83],"span",{"class":81,"line":82},"line",1,[79,84,86],{"class":85},"sJ8bj","#!\u002Fusr\u002Fbin\u002Fpython -tt\n",[79,88,89],{"class":81,"line":33},[79,90,91],{"emptyLinePlaceholder":20},"\n",[79,93,95],{"class":81,"line":94},3,[79,96,97],{"class":85},"# A script to get specified info from a URL\n",[79,99,101],{"class":81,"line":100},4,[79,102,103],{"class":85},"# Author Ando Roots 2010\n",[79,105,107],{"class":81,"line":106},5,[79,108,109],{"class":85},"# Usage: Specify the parameters with command line options.\n",[79,111,113],{"class":81,"line":112},6,[79,114,115],{"class":85},"# Usage: .\u002Ffetch_info.py URL Search_pattern_start Search_pattern_end\n",[79,117,119],{"class":81,"line":118},7,[79,120,121],{"class":85},"# EXAMPLE: Rate.ee number of online users\n",[79,123,125],{"class":81,"line":124},8,[79,126,127],{"class":85},"# .\u002Ffetch_info.py http:\u002F\u002Fwww.rate.ee\u002F 'amp;act=search\"&gt;\u003Cstrong>' ' &amp;raquo;\u003C\u002Fstrong>'\n",[79,129,131],{"class":81,"line":130},9,[79,132,91],{"emptyLinePlaceholder":20},[79,134,136,140],{"class":81,"line":135},10,[79,137,139],{"class":138},"szBVR","import",[79,141,143],{"class":142},"sVt8B"," sys\n",[79,145,147,149],{"class":81,"line":146},11,[79,148,139],{"class":138},[79,150,151],{"class":142}," urllib\n",[79,153,155,157],{"class":81,"line":154},12,[79,156,139],{"class":138},[79,158,159],{"class":142}," re\n",[79,161,163],{"class":81,"line":162},13,[79,164,91],{"emptyLinePlaceholder":20},[79,166,168],{"class":81,"line":167},14,[79,169,170],{"class":85},"# Fetch the souce code, find and print the information\n",[79,172,174,177,181],{"class":81,"line":173},15,[79,175,176],{"class":138},"def",[79,178,180],{"class":179},"sScJk"," fetch_info",[79,182,183],{"class":142},"(url, start, end):\n",[79,185,187],{"class":81,"line":186},16,[79,188,91],{"emptyLinePlaceholder":20},[79,190,192,195,198],{"class":81,"line":191},17,[79,193,194],{"class":142},"  sourceCode ",[79,196,197],{"class":138},"=",[79,199,200],{"class":142}," urllib.urlopen(url).read()\n",[79,202,204,207,209,212,215,219,222],{"class":81,"line":203},18,[79,205,206],{"class":142},"  expression ",[79,208,197],{"class":138},[79,210,211],{"class":142}," start ",[79,213,214],{"class":138},"+",[79,216,218],{"class":217},"sZZnC"," '(.*?)'",[79,220,221],{"class":138}," +",[79,223,224],{"class":142}," end\n",[79,226,228],{"class":81,"line":227},19,[79,229,91],{"emptyLinePlaceholder":20},[79,231,233],{"class":81,"line":232},20,[79,234,235],{"class":85},"  # Regular expression matching on the source code of the target URL\n",[79,237,239,242,244],{"class":81,"line":238},21,[79,240,241],{"class":142},"  match ",[79,243,197],{"class":138},[79,245,246],{"class":142}," re.compile(expression).search(sourceCode)\n",[79,248,250,253],{"class":81,"line":249},22,[79,251,252],{"class":138},"  if",[79,254,255],{"class":142}," match:\n",[79,257,259,263,266,269],{"class":81,"line":258},23,[79,260,262],{"class":261},"sj4cs","    print",[79,264,265],{"class":142}," match.group(",[79,267,268],{"class":261},"1",[79,270,271],{"class":142},")\n",[79,273,274,277],{"class":81,"line":5},[79,275,276],{"class":138},"  else",[79,278,279],{"class":142},":\n",[79,281,283,285],{"class":81,"line":282},25,[79,284,262],{"class":261},[79,286,287],{"class":217}," 'Did not find a match.'\n",[79,289,291,294,297],{"class":81,"line":290},26,[79,292,293],{"class":142},"  sys.exit(",[79,295,296],{"class":261},"0",[79,298,271],{"class":142},[79,300,302],{"class":81,"line":301},27,[79,303,91],{"emptyLinePlaceholder":20},[79,305,307,309,312],{"class":81,"line":306},28,[79,308,176],{"class":138},[79,310,311],{"class":179}," main",[79,313,314],{"class":142},"():\n",[79,316,318,320,323,326,329,332],{"class":81,"line":317},29,[79,319,252],{"class":138},[79,321,322],{"class":261}," len",[79,324,325],{"class":142},"(sys.argv) ",[79,327,328],{"class":138},"!=",[79,330,331],{"class":261}," 4",[79,333,279],{"class":142},[79,335,337,339],{"class":81,"line":336},30,[79,338,262],{"class":261},[79,340,341],{"class":217}," 'A script to get specified info from a URL by A. Roots'\n",[79,343,345,347],{"class":81,"line":344},31,[79,346,262],{"class":261},[79,348,349],{"class":217}," 'Usage: .\u002Ffetch_info.py URL Search_pattern_start Search_pattern_end'\n",[79,351,353,356,358],{"class":81,"line":352},32,[79,354,355],{"class":142},"    sys.exit(",[79,357,268],{"class":261},[79,359,271],{"class":142},[79,361,363],{"class":81,"line":362},33,[79,364,91],{"emptyLinePlaceholder":20},[79,366,368,371,373,376,379,381,384],{"class":81,"line":367},34,[79,369,370],{"class":142},"  fetch_info(sys.argv[",[79,372,268],{"class":261},[79,374,375],{"class":142},"], sys.argv[",[79,377,378],{"class":261},"2",[79,380,375],{"class":142},[79,382,383],{"class":261},"3",[79,385,386],{"class":142},"])\n",[79,388,390,392,394],{"class":81,"line":389},35,[79,391,293],{"class":142},[79,393,296],{"class":261},[79,395,271],{"class":142},[79,397,399],{"class":81,"line":398},36,[79,400,91],{"emptyLinePlaceholder":20},[79,402,404,407,410,413,416],{"class":81,"line":403},37,[79,405,406],{"class":138},"if",[79,408,409],{"class":261}," __name__",[79,411,412],{"class":138}," ==",[79,414,415],{"class":217}," '__main__'",[79,417,279],{"class":142},[79,419,421],{"class":81,"line":420},38,[79,422,423],{"class":142},"  main()\n",[425,426,427],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":32,"searchDepth":33,"depth":33,"links":429},[],"2012-05-11T01:15:22Z",[74],{},"anroots","\u002Fgists\u002F2656905",{"title":66,"description":32},"gists\u002F2656905","https:\u002F\u002Fgist.github.com\u002Fanroots\u002F2656905","9n_F_SZZw9KKedN8k-xO0z6HdgokgJa-5LAMF5X_2sc",1790228555254]