Regex to capture content or text after H1?

The Curator

Elite Member
Joined
Dec 27, 2013
Messages
1,512
Reaction score
761
I am using a cool scraping software, webharvy that will scrape title, meta, url, but I am having a tough time scraping the content of the page and I was thinking of doing it by identifying via regex any text/content found on the page after the H1 tag. I just don't understand regex to formulate this myself. Appreciate any help with it!
 
it's generally considered bad form to regex html. I think the first answer here does a good job of explaining why:

http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags

tldr: Use a parser actually made for parsing html
 
depending on how challenging the site is you trying to scrape i might write something up. post a link or pm me.
 
Yeah I saw someone recommending python to parse the html. I dont have those skills and webharvy doesnt utilize that option unfortunately.

What he said. Are you making it yourself? I have no idea what webharvy is, but going with a HTML parser + xpaths is a great way to do it.
 
xpath will change over time, but regex will always get what you need exactly

try this:

(?<=\<h1\>).*?(?=\<\/h1\>)
 
(.+) means everything so <h1>(.+)</h1> will capture everything in the title tag. if you want after you can do </h1>(.+)
 
I am using a cool scraping software, webharvy that will scrape title, meta, url, but I am having a tough time scraping the content of the page and I was thinking of doing it by identifying via regex any text/content found on the page after the H1 tag. I just don't understand regex to formulate this myself. Appreciate any help with it!
You can easily find id of tag in HTML and parse text by Id.
example.png

Can share this tool with bhw members - just send me send me request in PM.
48goy9r77
 
Back
Top