我是一只美丽的汤.我的挑战是:
我有一个3000个网址的列表,我用它来查找公司的名称。我想做的是:
这看起来很简单,但是我读过的所有教程都假设了一个用例,其中多个内容元素正在从一个单个url中被抓取,所以在我的示例中可以根据标记、属性等进行搜索,我无法检查每个网站的html,所以我需要搜索一个字符。
任何帮助都将不胜感激!
发布于 2018-09-27 14:00:25
以下几点应该能让你开始:
from bs4 import BeautifulSoup
import requests
import re
for url in ['http://www.apple.com/', 'http://www.google.com', 'http://www.stackoverflow.com/']:
html = requests.get(url)
soup = BeautifulSoup(html.content, 'html.parser')
for text in soup.stripped_strings:
if '©' in text:
text = re.sub(r'\s+', ' ', text) # condense any whitespace
print(f'"{url}" {text}')它将显示:
"http://www.apple.com/" Copyright © 2018 Apple Inc. All rights reserved.
"http://www.google.com" © 2018 -
"http://www.stackoverflow.com/" site design / logo © 2018 Stack Exchange Inc; user contributions licensed under使用Python 3.6.6进行测试
https://stackoverflow.com/questions/52458279
复制相似问题