簡體   English   中英

BeautifulSoup和輸出

[英]BeautifulSoup and Output

Python的新手,網頁抓取的新手。 為了練習,我正在嘗試抓取我學校的課程目錄。 對於專業而言,課程目錄是HTML頁面,其中包含部門中的課程列表。 我想抓取這些類名(成功)和描述(成功)。 但是,現在剩下2個(?)字符串列表,它們分別打印而沒有關聯。

import requests
from bs4 import BeautifulSoup

r = requests.get("")

data = r.text

soup = BeautifulSoup(data)

courses = soup.find_all('p',{'class' : 'courseblocktitle'})

descriptions = soup.find_all('p',{'class' : 'courseblockdesc'})

for course in courses:
    classes = course.get_text()
    print(classes)

for description in descriptions:
    desc = description.get_text()
    print(desc)

我只想打印沒有先決條件的課程(這些課程沒有任何唯一的標簽或任何內容-先決條件包括在課程說明中)。 我這樣做的想法是:

for description in descriptions:
    if 'prerequisite(s)' not in description:
        print(description)

但是,這並不能滿足我的要求。 我現在很迷路,我們將不勝感激。

最終,我想知道a)如何關聯我的兩個字符串列表(內容),以及b)如何僅打印那些沒有先決條件的字符串。

編者:“ http://collegecatalog.uchicago.edu/thecollege/geographicalstudies/

使用'courseblock main'獲取課程和說明,而不是嘗試同時獲取兩者並加入:

import requests
from bs4 import BeautifulSoup

r = requests.get("http://collegecatalog.uchicago.edu/thecollege/geographicalstudies/")

data = r.text

soup = BeautifulSoup(data)

courses = soup.find_all('div',{'class' : 'courseblock main'})


for course in courses:
    classes = course.get_text()
    if "Prerequisite(s)" not in classes:
        print(classes)


GEOG 20000.  Orientation Seminar.  100 Units.
This course is a review of the history and current orientations of human and environmental geography. It includes a critical review of representative pedagogic works and selected reading of recent periodical and monographic literature.
Instructor(s): M. Mikesell     Terms Offered: Autumn
Note(s): Open to current and prospective geographical studies majors; open to nonmajors with consent of instructor



GEOG 20100.  Cultural Geography.  100 Units.
This course examines the two main concerns of this field of geography: (1) the logic and pathology revealed in the record of the human use and misuse of the Earth, and (2) the discordant relationship of the world political map with more complicated patterns of linguistic and religious distribution.
Instructor(s): M. Mikesell     Terms Offered: Winter
Equivalent Course(s): ENST 25900,GEOG 30100



GEOG 21900.  Historical Geography of the United States.  100 Units.
This course examines the spatial dynamics of empire, the frontier, regional development, the social character of settlement patterns, and the evolution of the cultural landscapes of America from pre-European times to 1900. All-day northern Illinois field trip required.
Instructor(s): M. Conzen     Terms Offered: Autumn
Note(s): This course offered in even years.
Equivalent Course(s): GEOG 31900,HIST 28800,HIST 38800



GEOG 22100.  Changing America in the Twentieth Century.  100 Units.
This course explores the regional organization of U.S. society and its economy during the pivotal twentieth century, emphasizing the shifting dynamics that explain the spatial distribution of people, resources, economic activity, human settlement patterns, and mobility. We put special focus on the regional restructuring of industry and services, transportation, city growth, and cultural consumption. Two-day weekend field trip to the Mississippi River required.
Instructor(s): M. Conzen     Terms Offered: Winter
Note(s): This course offered odd years.
Equivalent Course(s): GEOG 32100,HIST 27506,HIST 37506



GEOG 22700.  Urban Structure and Process.  100 Units.
This course reviews competing theories of urban development, especially their ability to explain the changing nature of cities under the impact of advanced industrialism. Analysis includes a consideration of emerging metropolitan regions, the microstructure of local neighborhoods, and the limitations of the past U.S. experience as a way of developing worldwide urban policy.
Instructor(s): F. Stuart     Terms Offered: Winter
Equivalent Course(s): SOCI 20104,CRES 20104,GEOG 32700,SOCI 30104,SOSC 25100



GEOG 23003.  Urban Europe, 1600-Present.  100 Units.
This course examines the growth, structure, and, on occasion, decline of European towns and cities from the seventeenth century to the present. The focus throughout is on questions directly related to the positioning, form, and function of urban communities and to the efforts of interest groups and policy makers to shape and promote the fortunes of these communities. The course is interdisciplinary in spirit and content, drawing on the contributions of historians, geographers, sociologists, economists, demographers, political scientists, urban planners, and others. There are no prerequisites; the readings and lectures cover whatever needs to be known about theories, methods, and the European context.
Instructor(s): J. Craig     Terms Offered: Winter
Equivalent Course(s): HIST 23003,HIST 33003,GEOG 33003



GEOG 23500.  Urban Geography.  100 Units.
This course examines the spatial organization and current restructuring of modern cities in light of the economic, social, cultural, and political forces that shape them. It explores the systematic interactions between social process and physical system. We cover basic concepts of urbanism and urbanization, systems of cities urban growth, migration, centralization and decentralization, land-use dynamics, physical geography, urban morphology, and planning. Field trip in Chicago region required.
Instructor(s): M. Conzen     Terms Offered: Winter
Note(s): This course offered in even years.
Equivalent Course(s): GEOG 33500



GEOG 25300.  Seminar: Problems in the Human Geography of the Middle East.  100 Units.
This course includes a review and cartographic demonstration of habitat types, modes of livelihood, and ethnic distribution. Students then present reports on selected aspects of human geography.
Instructor(s): M. Mikesell     Terms Offered: Spring



GEOG 26100.  Roots of the Modern American City.  100 Units.
This course traces the economic, social, and physical development of the city in North America from pre-European times to the mid-twentieth century. We emphasize evolving regional urban systems, the changing spatial organization of people and land use in urban areas, and the developing distinctiveness of American urban landscapes. All-day Illinois field trip required.
Instructor(s): M. Conzen     Terms Offered: Autumn
Note(s): This course offered in odd years.
Equivalent Course(s): ENST 26100,GEOG 36100,HIST 28900,HIST 38900



GEOG 26300.  The Chinese Environment.  100 Units.
This course explores the changing interrelationship between humans and the physical environment in China. We begin by dealing with physical geography and the country's resource base. We then consider the human response to the opportunities offered by China's physical environment. Finally, we shift our emphasis to environmental problems. Students are required to attend both sessions.
Instructor(s): R. Edmonds     Terms Offered: Spring
Equivalent Course(s): ENST 26300,GEOG 36300



GEOG 28201.  Intro to Geographic Information Systems.  100 Units.
This course introduces students to the concepts and applications of geographic information systems (GIS). The course provides a basic foundation of spatial analysis and GIS with laboratory applications in particular techniques and methodology utilizing ESRI’s ArcGIS 10. Students will learn to perform spatial analyses and communicate their results through cartography, along with introduction to such concepts as spatial data collection, remote sensing, and database design.
Instructor(s): T. Schuble     Terms Offered: Autumn 
Note(s): Graduate students will be allowed to enroll for section 2
Equivalent Course(s): GEOG 38201



GEOG 28800.  History of Cartography.  100 Units.
This course offers a grand overview of the key developments in mapmaking throughout history worldwide, from pre-literate cartography to the modern interactive digital environment. It looks at the producers, their audience, the technologies and artistic systems used, and the human and global contexts in which they developed. The course also draws on the extensive map collections of Regenstein Library.
Instructor(s): G. Danzer     Terms Offered: Spring
Equivalent Course(s): GEOG 38800

要使用list comp獲得所有無條件的課程:

course_info = [crs.text for crs in soup.find_all('div',{'class' : 'courseblock main'}) if "Prerequisite(s)" not in crs.text]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM