【发布时间】:2018-10-17 19:08:17
【问题描述】:
我正在尝试抓取网站上的表格,然后将其转换为 CSV 表单。尽管有我的代码,但什么都没有出现。你能告诉我出了什么问题吗?
网址:http://www.multiclick.co.kr/sub/gamepatch/gamerank.html
不用担心语言。请在日历上比今天早一两天的任何时间设置日期,然后单击放大镜。然后你就可以看到一张桌子了。
# Load the required modules
import urllib
from bs4 import BeautifulSoup
import pandas as pd
# Open up the page
url = "http://www.multiclick.co.kr/sub/gamepatch/gamerank.html"
web_page = urllib.request.Request(
url,
data = None,
headers={'User-Agent': ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/35.0.1916.47 Safari/537.36")})
type(web_page)
web_page = urllib.request.urlopen(web_page)
# Parse the page
soup = BeautifulSoup(web_page, "html.parser")
print(soup)
# Get the table
# Get the columns
# Get the rows
# Stack them altogether
# Save it as a csv form
【问题讨论】:
-
你不能像那样抓取动态加载内容的页面。只是 fech
http://ws.api.thelog.co.kr/service/info/rank/RRRR-MM-DD(它只是 JSON)。 -
或者,如果你必须抓取,你可以使用 Selenium 来自动化浏览器并通过 ajax/动态页面工作
标签: python web-crawler