Python 2.7 BeautifulSoup web表刮削 从urllib2导入urlopen,请求 从bs4导入BeautifulSoup 场地https://racing.hkjc.com/racing/information/English/racing/LocalResults.aspx/' hdr={'User-Agent':'Mozilla/5.0'} req=请求(站点,标题=hdr) res=urlopen(请求) rawpage=res.read() page=rawpage.replace(“,”) soup=BeautifulSoup(第页,“html.parser”) table=soup.find(“table”,{“class”:“f_tac table_bd draggable”}) 打印(表格)

Python 2.7 BeautifulSoup web表刮削 从urllib2导入urlopen,请求 从bs4导入BeautifulSoup 场地https://racing.hkjc.com/racing/information/English/racing/LocalResults.aspx/' hdr={'User-Agent':'Mozilla/5.0'} req=请求(站点,标题=hdr) res=urlopen(请求) rawpage=res.read() page=rawpage.replace(“,”) soup=BeautifulSoup(第页,“html.parser”) table=soup.find(“table”,{“class”:“f_tac table_bd draggable”}) 打印(表格),python-2.7,screen-scraping,Python 2.7,Screen Scraping,这项工作完美地得到了一个表输出,直到我将url更改为下一页,没有任何输出(无) '' 请说明url或代码有什么问题?您必须将查询字符串添加到url的末尾: 例如: 要从第2页获取表,请执行以下操作: from urllib2 import urlopen, Request from bs4 import BeautifulSoup site = 'https://racing.hkjc.com/racing/information/English/racing/LocalResults.aspx

这项工作完美地得到了一个表输出,直到我将url更改为下一页,没有任何输出(无)

''


请说明url或代码有什么问题?

您必须将查询字符串添加到url的末尾:

例如: 要从第2页获取表,请执行以下操作:

from urllib2 import urlopen, Request
from bs4 import BeautifulSoup
site = 'https://racing.hkjc.com/racing/information/English/racing/LocalResults.aspx/'
hdr = {'User-Agent': 'Mozilla/5.0'}
req = Request(site, headers=hdr)
res = urlopen(req)
rawpage = res.read()
page = rawpage.replace("<!-->", "")
soup = BeautifulSoup(page, "html.parser")
table = soup.find("table", {"class":"f_tac table_bd draggable"})
print (table)
site ='https://racing.hkjc.com/racing/information/English/racing/LocalResults.aspx/?RaceDate=2020/03/14&Racecourse=ST&RaceNo=2'