@@ -1500,10 +1500,10 @@ def crawl_askahh() -> dict:
15001500 )
15011501
15021502 def crawl_ygpy () -> dict :
1503- def get_links (url : str , prefix : str ) -> list [str ]:
1503+ def get_links (url : str , prefix : str , regex : str = r'href="(/vpn/\d{4}/\d{2}.html)"' ) -> list [str ]:
15041504 content = utils .http_get (url = url )
15051505
1506- groups = re .findall (r'href="(/vpn/\d{4}/\d{2}.html)"' , content , flags = re .I )
1506+ groups = re .findall (regex , content , flags = re .I )
15071507 if not groups :
15081508 logger .warning (f"[AirPortCollector] cannot fetch article from url: { url } " )
15091509 return []
@@ -1534,6 +1534,32 @@ def get_links(url: str, prefix: str) -> list[str]:
15341534 if item and isinstance (item , dict ):
15351535 result .update (item )
15361536
1537+ # Extract javascript link from peer page and then parse airport urls and coupons
1538+ javascripts = utils .multi_thread_run (
1539+ func = get_links ,
1540+ tasks = [[x , base , r'href="(/assets/vpn_\d+_\d+.md.[A-Za-z0-9_\-]+.lean.js)"' ] for x in articles ],
1541+ )
1542+
1543+ airports = utils .multi_thread_run (
1544+ func = run_crawl ,
1545+ tasks = [
1546+ [
1547+ x [0 ],
1548+ r'"详细信息"|测试报告"|"官方(群组|频道)|"更新于|"联系方式' ,
1549+ r'{href:"(https?://[^\s]+/(?:#/register|auth)\?(?:code|invite)=[^\s]+)"}' ,
1550+ r'{code:"([^\r\n\s]+)"}' ,
1551+ ]
1552+ for x in javascripts
1553+ if x and isinstance (x , list )
1554+ ],
1555+ )
1556+
1557+ for item in airports :
1558+ if not item or not isinstance (item , dict ):
1559+ continue
1560+
1561+ result .update (item )
1562+
15371563 return result
15381564
15391565 def crawl_jctj (convert : bool = False ) -> dict :
@@ -1592,6 +1618,9 @@ def run_crawl(url: str, separator: str, address_regex: str, coupon_regex: str) -
15921618 return {}
15931619
15941620 for group in groups :
1621+ if not group or not isinstance (group , str ):
1622+ continue
1623+
15951624 words = re .findall (utils .trim (address_regex ), group , flags = re .M )
15961625 address = words [0 ] if words else ""
15971626 if not address :
0 commit comments