Hack Forums
[Python] Url Scraper - Regex - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Url Scraper - Regex (/showthread.php?tid=4520611)



Url Scraper - Regex - Only3 - Nov 3, 2014

wu guys saw many times ppl that ask about it
so i made simple function \ example

Python 3
PHP Code

<?php 
import urllib
.request, re

def Url_Scraper
(url,reg):
    
src = urllib.request.urlopen(url).read()
    match = 
re.findall(reg, str(src))
    for 
m in match:
           print(
m)

Url_Scraper('http://www.google.com','\href="(.*?)"') 

🤝 Enjoy


* - Mouse❤️ - Nov 3, 2014

What's with the rogue backslash in the 2nd param? \h isn't an escape character and I didn't know you could refer to string literals with just \ in python. I thought you would either just \Qstring literal here\E or just backslash the = and the "