我正试图从下面的网站上获取所有公司名称(突出显示)。这是我的第一次网络抓取工作,所以我正在努力理解为什么我不能抓取公司名称,尽管我有正确的参数
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'} # This is chrome, you can set whatever browser you like
request = requests.get("https://www.hispanicmeetings.org", verify=False, headers=headers)
soup = bs4.BeautifulSoup(request.content)
soup.find_all("a href") # this is not getting me company names
soup.find_all('alt') #this either
我在网页上找到了html标签,并尝试了许多小组合,但似乎没有任何效果。任何将所有公司名称集中到一个地方的建议对我来说都意义重大
您没有使用BeautifulSoup正确引用正确的标记和/或属性。我建议找一个关于html的小教程来理解标记和属性,然后看看如何使用bs4选择它们。然后,您可以看到如何拉出标记,并从这些标记中拉出文本和/或属性值。请尝试以下代码:
输出:
在类名为-Company的
<td>
标记中,公司名称作为alt
标记的img
属性出现您正在使用
soup.find_all('alt')
-alt
不是标记。 只能从soup对象中选择HTML标记,而不能从属性中选择相关问题 更多 >
编程相关推荐