Skip to content

Commit dc823e0

Browse files
authored
Merge pull request #148 from yamada-github-account/fix-pypi-search
Fix: PyPI web scraping syntax.
2 parents 5982ef3 + 0bf6aff commit dc823e0

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Pypi.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,24 @@ public function search($query)
2121
$this->id,
2222
$query,
2323
"{$this->search_url}{$query}",
24-
'/<tr class="(.*?)">([\s\S]*?)<\/tr>/i',
25-
2
24+
'/<a class="package-snippet" ([\s\S]*?)<\/a>/i',
25+
1
2626
);
2727

2828
foreach ($this->pkgs as $pkg) {
2929
// make params
3030
// name
31-
preg_match('/<a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
32-
$title = str_replace("&nbsp;", " ", strip_tags($matches[0]));
33-
$url = strip_tags($matches[1]);
31+
preg_match('/<span class="package-snippet__name">(.*?)<\/span>/i', $pkg, $matches);
32+
$title = str_replace("&nbsp;", " ", $matches[1]);
3433

35-
preg_match_all('/<td>([\s\S]*?)<\/td>/i', $pkg, $matches);
36-
$downloads = strip_tags($matches[1][1]);
37-
$details = strip_tags($matches[1][2]);
34+
preg_match('/href="(.*?)">/i', $pkg, $matches);
35+
$url = $matches[1];
36+
37+
preg_match('/<span class="package-snippet__version">(.*?)<\/span>/i', $pkg, $matches);
38+
$downloads = $matches[1];
39+
40+
preg_match('/<p class="package-snippet__description">(.*?)<\/p>/i', $pkg, $matches);
41+
$details = $matches[1];
3842

3943
$this->cache->w->result(
4044
$title,

0 commit comments

Comments
 (0)