【发布时间】:2018-07-13 20:09:00
【问题描述】:
我需要检查网页是否有版权符号 ©,如果有,我会提取包含该符号的标签文本。例如,对于网页“profile.theguardian.com/signin”,目标文本是“© 2018 Guardian News and Media Limited 或其关联公司。保留所有权利”。如何使用 Python 3.x 完成?
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup
我需要检查网页是否有版权符号 ©,如果有,我会提取包含该符号的标签文本。例如,对于网页“profile.theguardian.com/signin”,目标文本是“© 2018 Guardian News and Media Limited 或其关联公司。保留所有权利”。如何使用 Python 3.x 完成?
【问题讨论】:
标签: python python-3.x web-scraping beautifulsoup
我终于找到了我正在寻找的解决方案;
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)
希望这对其他人有所帮助。感谢那些试图提供帮助的人。
【讨论】:
您好,您应该在提交问题时发布示例代码,但以下内容应说明版权标志是否在特定页面上:
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")
【讨论】: