дополнительные параметры desc для кода Ege Özcan
function dynamicSort(property, desc) {
if (desc) {
return function (a, b) {
return (a[property] > b[property]) ? -1 : (a[property] < b[property]) ? 1 : 0;
}
}
return function (a, b) {
return (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
}
}
Привет, вам следует опубликовать свой образец кода при отправке вашего вопроса, но следующее должно указать, находится ли знак авторского права на определенной странице:
from bs4 import BeautifulSoup
import urllib.request
masterURL = 'https://profile.theguardian.com/signin'
sauce = urllib.request.urlopen(masterURL).read()
soup = BeautifulSoup(sauce,'lxml')
temp = soup.prettify().encode('UTF-8')
#\xc2\xa9 is unicode symbol for copyright sign
if(b'\xc2\xa9' in temp):
print('Copy Right On Page')
else:
print('No Copy Right on Page')
Принимая это как footer_copyright
, вы можете сделать:
from bs4 import BeautifulSoup
import urllib.request as url
BeautifulSoup(url.urlopen(masterURL).read()).select("p.footer__copyright")
Наконец я нашел решение, которое я искал,
URL = 'https://profile.theguardian.com/signin'
webpage = requests.get(URL)
soup = BeautifulSoup(webpage.content,'html.parser')
symbol = u'\N{COPYRIGHT SIGN}'.encode('utf-8')
symbol = symbol.decode('utf-8')
pattern = r'' + symbol
for tag in soup.findAll(text=re.compile(pattern)):
copyrightTexts = tag.parent.text
print(copyrightTexts)
Надеюсь, это поможет другим. Спасибо за тех, кто пытался помочь.