Python 组合与输出

Python 组合与输出,python,python-3.x,python-3.4,Python,Python 3.x,Python 3.4,Python新手,web抓取新手。为了练习,我正在努力整理学校的课程目录。对于专业而言,课程目录是一个HTML页面,其中包含该系的课程列表。我想删除这些类名(成功)和描述(成功)。但是,我现在只剩下两个字符串列表(?),它们单独打印,没有关联 import requests from bs4 import BeautifulSoup r = requests.get("") data = r.text soup = BeautifulSoup(data) courses = soup.f

Python新手,web抓取新手。为了练习,我正在努力整理学校的课程目录。对于专业而言,课程目录是一个HTML页面,其中包含该系的课程列表。我想删除这些类名(成功)和描述(成功)。但是,我现在只剩下两个字符串列表(?),它们单独打印,没有关联

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)如何只打印没有先决条件的字符串


Ed:“

使用
'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
要获得所有课程,无需使用列表补考:

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

如果您共享一个url,这样我们就可以看到页面的结构,这会有所帮助。有一对一的通信吗?也许你可以把这两个列表放在一起。如果你共享链接,过滤结果就很简单了