84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
A. 待抓取的页面的html:
html
$str2 = << ⑧北京汉奥汽配有限公司 主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉) 地址: 城环城B-01号 EOT;
⑧北京汉奥汽配有限公司
主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉)
地址: 城环城B-01号
B. 我写的抓取正则:
$reg_list = "/\s*\s*\s*\s*\s*\s*\s*\s*\s*<\/a>\s*<\/td>\s*<\/tr>\s*<\/table>\s*<\/td>\s*\s*\s*\s*[\x7f-\xff]+<\/a>\s*<\/p>\s*\s*主营:<\/span>\s*([\x7f-\xff ]+_-\.)<\/span>\s*<\/p>\s*\s*地址:<\/span>\s*([\x7f-\xff -_\.]+)<\/span>\s*<\/p>\s*<\/td>\s*<\/td>\s*<\/tr>\s*<\/table>\s*<\/p>/"; 编辑器中显示(截图): 之所以写成这么复杂是因为我要获取一下部分内容: 关键点来了,那么复杂,根本无法调试正则让他正确的抓取到我要的内容,请问各位大牛是如何写这样复杂的正则,然后调试,直到能够抓取到自己想要的数据的?? 2 0 0 过去多啦不再A梦 reply all (2) I'll reply Close 黄舟2017-05-16 13:18:30 2 floor It’s time to use the symfony/dom-crawler method again. DOM Dafa is good, if you retreat from the rules, you will stay safe composer.json { "require": { "symfony/css-selector": "^3.2", "symfony/dom-crawler": "^3.2" } } a.php ⑧北京汉奥汽配有限公司 主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉) 地址: 城环城B-01号 EOT; $dom = new Crawler(); $dom->addHtmlContent($str2, 'UTF-8'); $imgSrc = $dom->filter('td.imgp')->filter('img')->attr('src'); $productName = $dom->filter('td.propList')->filter('p.productName>a')->text(); $productProp6 = $dom->filter('td.propList')->filter('p.productProp6>.propValue')->text(); $productProp4 = $dom->filter('td.propList')->filter('p.productProp4>.propValue')->text(); var_dump($imgSrc); echo ''; var_dump($productName); echo ''; var_dump($productProp6); echo ''; var_dump($productProp4); echo ''; Output Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply 巴扎黑2017-05-16 13:18:30 1 floor DOM is naturally a better choice, but it’s not necessarily impossible to do it with regular methods. /alt=\'(?P[^\']+)\'(?:.+?)?src=\'(?P[^\']+)\'(?:.+?)?主营:(?:.+?)?\'>(?P[^<]+)(?:.+?)?地址:(?:.+?)?\'>(?P[^<]+)/s Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply Popular Topics More> What size is a5 paper Registration domain name query tool The difference between nohup and & Introduction to the meaning of += in C language Popular Articles Crypto Influencer Dark Defender Posts Viral XRP Price Prediction Following Ripple's Win Against SEC Michael Saylor Flags Bitcoin's Volatility As A Feature, Not A Bug SOL and ETH's Love-Hate Relationship, XRP's Moment in the Spotlight, USDe Goes Multi-Chain, Aave's Cashing In on Crypto Chaos, Trump Jr. And Eric Trump's Crypto Tease Review: Ugreen Nexode 100W 20000mAh Power Bank Offers Ample Juice to Go Bitcoin (BTC) Briefly Rose Above $60K But Gave Up Gains to Trade Around the $60K Mark, Mimicking Moves in Equities Markets Popular Tutorials More> Related Tutorials Popular Recommendations Latest courses The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 PHP introductory tutorial one: Learn PHP in one week 4206448 JAVA Beginner's Video Tutorial 2347187 The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 JAVA Beginner's Video Tutorial 2347187 Little Turtle's zero-based introduction to learning Python video tutorial 493059 Quick introduction to web front-end development 213403 Master PS video tutorials from scratch 842469 [Web front-end] Node.js quick start 3073 Complete collection of foreign web development full-stack courses 2480 Go language practical GraphQL 1958 550W fan master learns JavaScript from scratch step by step 464 Python master Mosh, a beginner with zero basic knowledge can get started in 6 hours 10689 Latest Downloads More> Web Effects Website Source Code Website Materials Front End Template [form button] jQuery enterprise message form contact code [Player special effects] HTML5 MP3 music box playback effects [Menu navigation] HTML5 cool particle animation navigation menu special effects [form button] jQuery visual form drag and drop editing code [Player special effects] VUE.JS imitation Kugou music player code [html5 special effects] Classic html5 pushing box game [Picture special effects] jQuery scrolling to add or reduce image effects [Photo album effects] CSS3 personal album cover hover zoom effect [Bootstrap template] Organic fruit and vegetable supplier web template Bootstrap5 [backend template] Bootstrap3 multifunctional data information background management responsive web page template-Novus [Bootstrap template] Real estate resource service platform web page template Bootstrap5 [Bootstrap template] Simple resume information web template Bootstrap4 [Bootstrap template] bootstrap responsive widescreen book education website template-DREAMLIFE [backend template] MAC style responsive blue enterprise CMS background management system template [backend template] Responsive gradient atmosphere background management system website template-usinessbox [Bootstrap template] Responsive vegetable and fruit store website template-Organio [PNG material] Cute summer elements vector material (EPS PNG) [PNG material] Four red 2023 graduation badges vector material (AI EPS PNG) [banner picture] Singing bird and cart filled with flowers design spring banner vector material (AI EPS) [PNG material] Golden graduation cap vector material (EPS PNG) [PNG material] Black and white style mountain icon vector material (EPS PNG) [PNG material] Superhero silhouette vector material (EPS PNG) with different color cloaks and different poses [banner picture] Flat style Arbor Day banner vector material (AI+EPS) [PNG material] Nine comic-style exploding chat bubbles vector material (EPS+PNG) [Front-end template] Home Decor Cleaning and Repair Service Company Website Template [Front-end template] Fresh color personal resume guide page template [Front-end template] Designer Creative Job Resume Web Template [Front-end template] Modern engineering construction company website template [Front-end template] Responsive HTML5 template for educational service institutions [Front-end template] Online e-book store mall website template [Front-end template] IT technology solves Internet company website template [Front-end template] Purple style foreign exchange trading service website template About us Disclaimer Sitemap php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
\s*
\s*[\x7f-\xff]+<\/a>\s*<\/p>\s*\s*主营:<\/span>\s*([\x7f-\xff ]+_-\.)<\/span>\s*<\/p>\s*\s*地址:<\/span>\s*([\x7f-\xff -_\.]+)<\/span>\s*<\/p>\s*<\/td>\s*<\/td>\s*<\/tr>\s*<\/table>\s*<\/p>/"; 编辑器中显示(截图): 之所以写成这么复杂是因为我要获取一下部分内容: 关键点来了,那么复杂,根本无法调试正则让他正确的抓取到我要的内容,请问各位大牛是如何写这样复杂的正则,然后调试,直到能够抓取到自己想要的数据的?? 2 0 0 过去多啦不再A梦 reply all (2) I'll reply Close 黄舟2017-05-16 13:18:30 2 floor It’s time to use the symfony/dom-crawler method again. DOM Dafa is good, if you retreat from the rules, you will stay safe composer.json { "require": { "symfony/css-selector": "^3.2", "symfony/dom-crawler": "^3.2" } } a.php ⑧北京汉奥汽配有限公司 主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉) 地址: 城环城B-01号 EOT; $dom = new Crawler(); $dom->addHtmlContent($str2, 'UTF-8'); $imgSrc = $dom->filter('td.imgp')->filter('img')->attr('src'); $productName = $dom->filter('td.propList')->filter('p.productName>a')->text(); $productProp6 = $dom->filter('td.propList')->filter('p.productProp6>.propValue')->text(); $productProp4 = $dom->filter('td.propList')->filter('p.productProp4>.propValue')->text(); var_dump($imgSrc); echo ''; var_dump($productName); echo ''; var_dump($productProp6); echo ''; var_dump($productProp4); echo ''; Output Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply 巴扎黑2017-05-16 13:18:30 1 floor DOM is naturally a better choice, but it’s not necessarily impossible to do it with regular methods. /alt=\'(?P[^\']+)\'(?:.+?)?src=\'(?P[^\']+)\'(?:.+?)?主营:(?:.+?)?\'>(?P[^<]+)(?:.+?)?地址:(?:.+?)?\'>(?P[^<]+)/s Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply Popular Topics More> What size is a5 paper Registration domain name query tool The difference between nohup and & Introduction to the meaning of += in C language Popular Articles Crypto Influencer Dark Defender Posts Viral XRP Price Prediction Following Ripple's Win Against SEC Michael Saylor Flags Bitcoin's Volatility As A Feature, Not A Bug SOL and ETH's Love-Hate Relationship, XRP's Moment in the Spotlight, USDe Goes Multi-Chain, Aave's Cashing In on Crypto Chaos, Trump Jr. And Eric Trump's Crypto Tease Review: Ugreen Nexode 100W 20000mAh Power Bank Offers Ample Juice to Go Bitcoin (BTC) Briefly Rose Above $60K But Gave Up Gains to Trade Around the $60K Mark, Mimicking Moves in Equities Markets Popular Tutorials More> Related Tutorials Popular Recommendations Latest courses The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 PHP introductory tutorial one: Learn PHP in one week 4206448 JAVA Beginner's Video Tutorial 2347187 The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 JAVA Beginner's Video Tutorial 2347187 Little Turtle's zero-based introduction to learning Python video tutorial 493059 Quick introduction to web front-end development 213403 Master PS video tutorials from scratch 842469 [Web front-end] Node.js quick start 3073 Complete collection of foreign web development full-stack courses 2480 Go language practical GraphQL 1958 550W fan master learns JavaScript from scratch step by step 464 Python master Mosh, a beginner with zero basic knowledge can get started in 6 hours 10689 Latest Downloads More> Web Effects Website Source Code Website Materials Front End Template [form button] jQuery enterprise message form contact code [Player special effects] HTML5 MP3 music box playback effects [Menu navigation] HTML5 cool particle animation navigation menu special effects [form button] jQuery visual form drag and drop editing code [Player special effects] VUE.JS imitation Kugou music player code [html5 special effects] Classic html5 pushing box game [Picture special effects] jQuery scrolling to add or reduce image effects [Photo album effects] CSS3 personal album cover hover zoom effect [Bootstrap template] Organic fruit and vegetable supplier web template Bootstrap5 [backend template] Bootstrap3 multifunctional data information background management responsive web page template-Novus [Bootstrap template] Real estate resource service platform web page template Bootstrap5 [Bootstrap template] Simple resume information web template Bootstrap4 [Bootstrap template] bootstrap responsive widescreen book education website template-DREAMLIFE [backend template] MAC style responsive blue enterprise CMS background management system template [backend template] Responsive gradient atmosphere background management system website template-usinessbox [Bootstrap template] Responsive vegetable and fruit store website template-Organio [PNG material] Cute summer elements vector material (EPS PNG) [PNG material] Four red 2023 graduation badges vector material (AI EPS PNG) [banner picture] Singing bird and cart filled with flowers design spring banner vector material (AI EPS) [PNG material] Golden graduation cap vector material (EPS PNG) [PNG material] Black and white style mountain icon vector material (EPS PNG) [PNG material] Superhero silhouette vector material (EPS PNG) with different color cloaks and different poses [banner picture] Flat style Arbor Day banner vector material (AI+EPS) [PNG material] Nine comic-style exploding chat bubbles vector material (EPS+PNG) [Front-end template] Home Decor Cleaning and Repair Service Company Website Template [Front-end template] Fresh color personal resume guide page template [Front-end template] Designer Creative Job Resume Web Template [Front-end template] Modern engineering construction company website template [Front-end template] Responsive HTML5 template for educational service institutions [Front-end template] Online e-book store mall website template [Front-end template] IT technology solves Internet company website template [Front-end template] Purple style foreign exchange trading service website template About us Disclaimer Sitemap php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
\s*主营:<\/span>\s*([\x7f-\xff ]+_-\.)<\/span>\s*<\/p>\s*\s*地址:<\/span>\s*([\x7f-\xff -_\.]+)<\/span>\s*<\/p>\s*<\/td>\s*<\/td>\s*<\/tr>\s*<\/table>\s*<\/p>/"; 编辑器中显示(截图): 之所以写成这么复杂是因为我要获取一下部分内容: 关键点来了,那么复杂,根本无法调试正则让他正确的抓取到我要的内容,请问各位大牛是如何写这样复杂的正则,然后调试,直到能够抓取到自己想要的数据的?? 2 0 0 过去多啦不再A梦 reply all (2) I'll reply Close 黄舟2017-05-16 13:18:30 2 floor It’s time to use the symfony/dom-crawler method again. DOM Dafa is good, if you retreat from the rules, you will stay safe composer.json { "require": { "symfony/css-selector": "^3.2", "symfony/dom-crawler": "^3.2" } } a.php ⑧北京汉奥汽配有限公司 主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉) 地址: 城环城B-01号 EOT; $dom = new Crawler(); $dom->addHtmlContent($str2, 'UTF-8'); $imgSrc = $dom->filter('td.imgp')->filter('img')->attr('src'); $productName = $dom->filter('td.propList')->filter('p.productName>a')->text(); $productProp6 = $dom->filter('td.propList')->filter('p.productProp6>.propValue')->text(); $productProp4 = $dom->filter('td.propList')->filter('p.productProp4>.propValue')->text(); var_dump($imgSrc); echo ''; var_dump($productName); echo ''; var_dump($productProp6); echo ''; var_dump($productProp4); echo ''; Output Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply 巴扎黑2017-05-16 13:18:30 1 floor DOM is naturally a better choice, but it’s not necessarily impossible to do it with regular methods. /alt=\'(?P[^\']+)\'(?:.+?)?src=\'(?P[^\']+)\'(?:.+?)?主营:(?:.+?)?\'>(?P[^<]+)(?:.+?)?地址:(?:.+?)?\'>(?P[^<]+)/s Like+0 Add Reply 关闭回复 过去多啦不再A梦 reply Popular Topics More> What size is a5 paper Registration domain name query tool The difference between nohup and & Introduction to the meaning of += in C language Popular Articles Crypto Influencer Dark Defender Posts Viral XRP Price Prediction Following Ripple's Win Against SEC Michael Saylor Flags Bitcoin's Volatility As A Feature, Not A Bug SOL and ETH's Love-Hate Relationship, XRP's Moment in the Spotlight, USDe Goes Multi-Chain, Aave's Cashing In on Crypto Chaos, Trump Jr. And Eric Trump's Crypto Tease Review: Ugreen Nexode 100W 20000mAh Power Bank Offers Ample Juice to Go Bitcoin (BTC) Briefly Rose Above $60K But Gave Up Gains to Trade Around the $60K Mark, Mimicking Moves in Equities Markets Popular Tutorials More> Related Tutorials Popular Recommendations Latest courses The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 PHP introductory tutorial one: Learn PHP in one week 4206448 JAVA Beginner's Video Tutorial 2347187 The latest ThinkPHP 5.1 world premiere video tutorial (60 days to become a PHP expert online training course) 1394746 JAVA Beginner's Video Tutorial 2347187 Little Turtle's zero-based introduction to learning Python video tutorial 493059 Quick introduction to web front-end development 213403 Master PS video tutorials from scratch 842469 [Web front-end] Node.js quick start 3073 Complete collection of foreign web development full-stack courses 2480 Go language practical GraphQL 1958 550W fan master learns JavaScript from scratch step by step 464 Python master Mosh, a beginner with zero basic knowledge can get started in 6 hours 10689 Latest Downloads More> Web Effects Website Source Code Website Materials Front End Template [form button] jQuery enterprise message form contact code [Player special effects] HTML5 MP3 music box playback effects [Menu navigation] HTML5 cool particle animation navigation menu special effects [form button] jQuery visual form drag and drop editing code [Player special effects] VUE.JS imitation Kugou music player code [html5 special effects] Classic html5 pushing box game [Picture special effects] jQuery scrolling to add or reduce image effects [Photo album effects] CSS3 personal album cover hover zoom effect [Bootstrap template] Organic fruit and vegetable supplier web template Bootstrap5 [backend template] Bootstrap3 multifunctional data information background management responsive web page template-Novus [Bootstrap template] Real estate resource service platform web page template Bootstrap5 [Bootstrap template] Simple resume information web template Bootstrap4 [Bootstrap template] bootstrap responsive widescreen book education website template-DREAMLIFE [backend template] MAC style responsive blue enterprise CMS background management system template [backend template] Responsive gradient atmosphere background management system website template-usinessbox [Bootstrap template] Responsive vegetable and fruit store website template-Organio [PNG material] Cute summer elements vector material (EPS PNG) [PNG material] Four red 2023 graduation badges vector material (AI EPS PNG) [banner picture] Singing bird and cart filled with flowers design spring banner vector material (AI EPS) [PNG material] Golden graduation cap vector material (EPS PNG) [PNG material] Black and white style mountain icon vector material (EPS PNG) [PNG material] Superhero silhouette vector material (EPS PNG) with different color cloaks and different poses [banner picture] Flat style Arbor Day banner vector material (AI+EPS) [PNG material] Nine comic-style exploding chat bubbles vector material (EPS+PNG) [Front-end template] Home Decor Cleaning and Repair Service Company Website Template [Front-end template] Fresh color personal resume guide page template [Front-end template] Designer Creative Job Resume Web Template [Front-end template] Modern engineering construction company website template [Front-end template] Responsive HTML5 template for educational service institutions [Front-end template] Online e-book store mall website template [Front-end template] IT technology solves Internet company website template [Front-end template] Purple style foreign exchange trading service website template About us Disclaimer Sitemap php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
\s*地址:<\/span>\s*([\x7f-\xff -_\.]+)<\/span>\s*<\/p>\s*<\/td>\s*<\/td>\s*<\/tr>\s*<\/table>\s*<\/p>/";
编辑器中显示(截图):
之所以写成这么复杂是因为我要获取一下部分内容:
关键点来了,那么复杂,根本无法调试正则让他正确的抓取到我要的内容,请问各位大牛是如何写这样复杂的正则,然后调试,直到能够抓取到自己想要的数据的??
It’s time to use the symfony/dom-crawler method again. DOM Dafa is good, if you retreat from the rules, you will stay safe
composer.json
{ "require": { "symfony/css-selector": "^3.2", "symfony/dom-crawler": "^3.2" } }
a.php
⑧北京汉奥汽配有限公司 主营: 大众 新速腾 新迈腾 新桑塔纳 新捷达 CC 新帕萨特 新宝来 收事故车及残值(郭京汉) 地址: 城环城B-01号 EOT; $dom = new Crawler(); $dom->addHtmlContent($str2, 'UTF-8'); $imgSrc = $dom->filter('td.imgp')->filter('img')->attr('src'); $productName = $dom->filter('td.propList')->filter('p.productName>a')->text(); $productProp6 = $dom->filter('td.propList')->filter('p.productProp6>.propValue')->text(); $productProp4 = $dom->filter('td.propList')->filter('p.productProp4>.propValue')->text(); var_dump($imgSrc); echo ''; var_dump($productName); echo ''; var_dump($productProp6); echo ''; var_dump($productProp4); echo '';
Output
DOM is naturally a better choice, but it’s not necessarily impossible to do it with regular methods.
/alt=\'(?P[^\']+)\'(?:.+?)?src=\'(?P[^\']+)\'(?:.+?)?主营:(?:.+?)?\'>(?P[^<]+)(?:.+?)?地址:(?:.+?)?\'>(?P[^<]+)/s
It’s time to use the symfony/dom-crawler method again. DOM Dafa is good, if you retreat from the rules, you will stay safe
composer.json
a.php
Output
DOM is naturally a better choice, but it’s not necessarily impossible to do it with regular methods.