Using Regular Expression To Extract All URLs

allsystems

Client
Регистрация
08.07.2013
Сообщения
81
Благодарностей
1
Баллы
8
Hi Guys,

I am trying to extract all URL on a webpage. I am trying to use regex but none seem to work. Is there a good regex to extract all URLs on page?

Thanks
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 264
Благодарностей
5 852
Баллы
113
Regex can be easily create in ZennoPoster. You should get source code of web page, copy it to regex constructor and put start and end of text.
Create_regex.png
 

allsystems

Client
Регистрация
08.07.2013
Сообщения
81
Благодарностей
1
Баллы
8
Only issue with this is that I am visiting random URLs so I dont know the format on each page which is why I need a super regex that works in Zenno and will get me 99.9% of all URLs
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
Extract all hrefs and you will be fine. You can try to look also on xpath for that. Not only regex and see what works best for you...
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 264
Благодарностей
5 852
Баллы
113

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
I use this one to capture urls in format:

Код:
http://domain.com/
https://domain.com/

http://www.domain.com/
https://www.domain.com/
My regex:

Код:
(?<=https?://(?:www\.)?)(?!www\.).*?(?=['/"]|</a>)
Maybe someone can improve it?
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 264
Благодарностей
5 852
Баллы
113

shabbysquire

Client
Регистрация
25.11.2012
Сообщения
544
Благодарностей
26
Баллы
28
Код:
(?<=href=")http.*?\.com
The only issue is the domain ext, some are: .co.uk, .mobi, etc.
 

VladZen

Administrator
Команда форума
Регистрация
05.11.2014
Сообщения
22 264
Благодарностей
5 852
Баллы
113

CSS

Client
Регистрация
22.05.2010
Сообщения
1 327
Благодарностей
663
Баллы
113
I use this one to capture urls in format:

Код:
http://domain.com/
https://domain.com/

http://www.domain.com/
https://www.domain.com/
My regex:

Код:
(?<=https?://(?:www\.)?)(?!www\.).*?(?=['/"]|</a>)
Maybe someone can improve it?
Sure, try this:
Код:
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:/~\+#]*[\w\-\@?^=%&amp;/~\+#])?
Also you can view Russian sector, there is regex list for typical tasks
 
  • Спасибо
Реакции: kveldulv и VladZen

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)