Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scrape multiple lines with regex
#1
basically i wish to scrape content between two tags with mulitiple lines in between, ignoring other tags until it matches the one i look for.

i know (.*?) works for some content between two tags.
Reply
#2
There's a flag for that (M or MULTILINE or (?m)).

import re

re.compile('X.*?Y', re.M)
What do you mean by tag? You're not trying to parse HTML with a regex, are you? That's generally a bad idea. Parsers designed for HTML are much better.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Regex against HTML/XML is not a good combination,a funny read.
There is a reason why parsers exist eg BeautifulSoup,lmxl...ect.
Parsers mention over can also take regex as help if needed.
Have a tutorial here.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Scrape table from multiple pages Nhattanktnn 1 793 Jun-07-2023, 09:35 AM
Last Post: Larz60+
  scrape data 1 go to next page scrape data 2 and so on alkaline3 6 5,056 Mar-13-2020, 07:59 PM
Last Post: alkaline3
  Scrape multiple urls LXML santdoyle 1 3,496 Oct-26-2019, 09:53 PM
Last Post: snippsat
  How to add multiple lines response in chatterbot? PrateekG 13 8,329 May-18-2018, 07:36 AM
Last Post: buran
  Scrape Multiple items from a webpage Prince_Bhatia 2 3,277 Sep-12-2017, 06:08 AM
Last Post: Prince_Bhatia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020