Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python模式库中删除链接_Python_Design Patterns_Screen Scraping - Fatal编程技术网

在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 

模式库和靓汤有什么区别?模式库和靓汤有什么区别?