代码拉取完成,页面将自动刷新
#! /usr/bin/env python3
# coding=utf-8
from bs4 import BeautifulSoup
import re
class Parse():
# new_urls, new_data = self.parse.Parser(new_url, html)
def Parser(self, new_url, html):
soup = BeautifulSoup(html, "html.parser", from_encoding="utf-8")
new_urls = self._get_new_urls(soup)
#new_data = self._get_new_data(new_url, soup)
return new_urls
def _get_new_urls(self, soup):
new_urls = set()
links = soup.find_all("span", class_="plid")
for link in links:
new_urls.add(((link.get_text()).split())[1])
return new_urls
'''
def _get_new_data(self, new_url, soup):
new_data = {}
new_data["url"] = new_url
links1 = soup.find("div", class_="vote-container").find_all("li", text=re.compile(r"Size"))
new_data["Size"] = links1[0].get_text()
links2 = soup.find("div", class_="vote-container").find_all("a", target=re.compile(r"_blank"))
if len(links2) != 0:
new_data["Source_html"]= (links2[0])["href"]
new_data["Source_text"]= links2[0].get_text()
links3 = soup.find("div", class_="vote-container").find_all("span", id = re.compile(r"post"))
new_data["Score"] = links3[0].get_text()
return new_data
'''
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。