在Python模式库中删除链接
我在一门课程中发现了类似的代码。此代码获取网页源代码中提到的特定格式的所有链接。除了最后一行,我什么都懂。最后一行是这样说的:在Python模式库中删除链接,python,design-patterns,screen-scraping,Python,Design Patterns,Screen Scraping,我在一门课程中发现了类似的代码。此代码获取网页源代码中提到的特定格式的所有链接。除了最后一行,我什么都懂。最后一行是这样说的: print link.attrs.get('href', '') 这是可行的,但是我不确定指导老师是如何做到这一点的。我查阅了文档,不知道是什么。get做了什么。有人能告诉我怎样才能找到这些信息吗 模式库文档: 它将获得该页面中的所有href“超链接”。您可以美化更方便的套餐 from bs4 import BeautifulSoup xml = requests.
print link.attrs.get('href', '')
这是可行的,但是我不确定指导老师是如何做到这一点的。我查阅了文档,不知道是什么。get做了什么。有人能告诉我怎样才能找到这些信息吗
模式库文档:
它将获得该页面中的所有href“超链接”。您可以美化更方便的套餐
from bs4 import BeautifulSoup
xml = requests.get("https://www.realclearpolitics.com/epolls/2010/governor/2010_elections_governor_map.html")
soup = BeautifulSoup(xml, "lxml") # lxml is just the parser for reading the html
soup.find_all('a href') # this is the line that does what you want
它将获得该页面中的所有href“超链接”。您可以美化更方便的套餐
from bs4 import BeautifulSoup
xml = requests.get("https://www.realclearpolitics.com/epolls/2010/governor/2010_elections_governor_map.html")
soup = BeautifulSoup(xml, "lxml") # lxml is just the parser for reading the html
soup.find_all('a href') # this is the line that does what you want
模式库和靓汤有什么区别?模式库和靓汤有什么区别?