PHP를 사용하여 웹 사이트에서 클래스 이름 스크래핑 (Scraping class name on a website using php)


문제 설명

PHP를 사용하여 웹 사이트에서 클래스 이름 스크래핑 (Scraping class name on a website using php)

그래서 웹사이트에서 클래스 이름을 스크레이핑하고 싶습니다. html 코드 소스는 다음과 같습니다.

<td title="Complexity" class="cvss6" itemscope itemtype="http://schema.org/Rating">

"cvss6" 다음과 같이 시도했습니다.

$nilai1 = explode('<td title="Complexity" class="', $kodeHTML);
$nilai_show2 = explode('" itemscope="', $nilai1[1]);echo "

<tr><td width='85%' align='left' bgcolor='#F5F5F5'>".$judul_show[0]."</td>";

if($nilai_show2[0] == 'cvss6') {
echo "<td width='15%' align='center' bgcolor='#FF0000'>High</td></tr>";

                    }

하지만 작동하지 않고 내 사이트에 아무 것도 표시되지 않습니다. html 일반 텍스트를 스크레이핑했습니다. 하지만 클래스 이름 안에 있는 텍스트를 어떻게 스크레이핑합니까? 감사합니다


참조 솔루션

방법 1:

To answer your question you could use regular expression to find what you need, with code below we try to find term that expect class="something" with multiline flag (https://www.php.net/manual/fr/function.preg‑match‑all.php) :

preg_match_all(
    '/class="(.+?)"/m',
    '<b>exemple : </b><div class="test test1 test2 test3" align=left>This is a test</div class="t1 t2">',
    $out
);

var_dump($out[1]);

/* output
  array(2) {
    [0]=>
    string(22) "test test1 test2 test3"
    [1]=>
    string(5) "t1 t2"
  }
*/

Also i advice you to use an library to crawl web page with php.

https://symfony.com/doc/current/components/dom_crawler.html

(by lountee ngemutLounis)

참조 문서

  1. Scraping class name on a website using php (CC BY‑SA 2.5/3.0/4.0)

#web-crawler #PHP






관련 질문

UnicodeError: URL에 ASCII가 아닌 문자가 포함되어 있습니다(Python 2.7). (UnicodeError: URL contains non-ASCII characters (Python 2.7))

크롤링 출력 - 두 변수 연결 (Crawling output - connecting two variables)

Python2.7에서 효과적인 크롤러를 만드는 방법 (How to make an effective crawler in Python2.7)

이 텍스트가 다른 기사의 일부임을 Google에 알리는 방법 (How to tell google this text is part of another article)

크롤링하는 HTML 페이지에서 JavaScript 개체를 구문 분석하는 방법은 무엇입니까? (How to parse a JavaScript object from a HTML page I crawl?)

데이터 크롤링 또는 API 사용 (Crawling data or using API)

파이썬을 사용하여 웹사이트에서 내부 링크만 크롤링 (Crawl only internal links from a website using python)

받은 응답에서 HTML 코드를 긁는 방법은 무엇입니까? (How to scrape the html code from the response received?)

PHP를 사용하여 웹 사이트에서 클래스 이름 스크래핑 (Scraping class name on a website using php)

Scrapy Spider를 사용하는 Craigslist Scraper가 기능을 수행하지 않음 (Craigslist Scraper using Scrapy Spider not performing functions)

BeautifulSoup: 이 링크에서 모든 기사 링크를 가져오는 방법은 무엇입니까? (BeautifulSoup: how to get all article links from this link?)

나는 클라이언트입니다. 선택적으로 http 응답에서 헤더를 제거할 수 있습니까? (I'm client. Can I remove header from http response optionally?)







코멘트