如何解决另一个菜鸟网问题:如何将这个pythonscrape的内容拉到我的R中的全局环境中?
以下来自我正在使用的 python 的抓取。我已经删除了一些内容,但我会尽力解释。 我想在循环遍历我的参数时提取我的刮擦的内容。我希望每个单独参数的内容在 R 中出现在我的全局环境中,以便我可以继续在 R 中进行清理。
class Scrape(object):
...
def main(self,pol,sdate,edate,region,prefix,dataSource):
url = "http://rhone/cgi-bin/data_extract.pl"
cont = []
d = self.data(url,dataSource)
# bs below
soup = BeautifulSoup(d.text,'html.parser')
pres = soup.find('pre')
try:
cont = pres.contents
except:
print("! No data")
print(len(cont))
my_dict = {}
outname = str(pol)
my_dict[outname] = cont
return (my_dict[outname])
cont.clear()
def loopMain(self):
count = 1
for pc in self.polcodes:
# print(str(count) + ".",pc)
print("{0:2}. {1:10}".format(count,pc))
self.main(pc,self.sdate,self.edate,self.region,self.prefix,self.dataSource)
count += 1
print("...Done. ")
if __name__ == '__main__':
ref = Scrape('00-01-2020','11-31-2020','6','ELP')
ref.loopMain()
我想将每个 polcode 分配给我在 R 中运行时出现在我的全局环境中的数据帧。
library(reticulate)
py_run_file("webscrape_R.py")
我尝试在我的全局环境中使用下面的这一点进行输出,但没有奏效。
my_dict = {}
outname = str(pol)
my_dict[outname] = cont
return (my_dict[outname])
cont.clear()
不幸的是,我正在抓取的站点需要服务器连接,因此不是最好的复制。但我会回答任何问题以提供帮助。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。